1
- import json
2
-
3
1
from django .db import NotSupportedError
4
- from django .db .models import JSONField
5
2
from django .db .models .fields .json import (
6
3
ContainedBy ,
7
4
DataContains ,
@@ -28,20 +25,6 @@ def data_contains(self, compiler, connection): # noqa: ARG001
28
25
raise NotSupportedError ("contains lookup is not supported on this database backend." )
29
26
30
27
31
- _from_db_value = JSONField .from_db_value
32
-
33
-
34
- def from_db_value (self , value , expression , connection ):
35
- """
36
- Transforms the value retrieved from the database into a string if the database
37
- vendor is MongoDB. This is necessary because MongoDB saves the data as a
38
- dictionary, and converting it to a JSON string allows for proper decoding.
39
- """
40
- if connection .vendor == "mongodb" :
41
- value = json .dumps (value )
42
- return _from_db_value (self , value , expression , connection )
43
-
44
-
45
28
def has_key_lookup (self , compiler , connection ):
46
29
rhs = self .rhs
47
30
lhs = process_lhs (self , compiler , connection )
@@ -155,7 +138,6 @@ def register_json_field():
155
138
HasKeyLookup .as_mql = has_key_lookup
156
139
HasKeys .mongo_operator = "$and"
157
140
JSONExact .process_rhs = json_process_rhs
158
- JSONField .from_db_value = from_db_value
159
141
KeyTransform .as_mql = key_transform
160
142
KeyTransformIn .as_mql = key_transform_in
161
143
KeyTransformIsNull .as_mql = key_transform_isnull
0 commit comments