@@ -46,13 +46,8 @@ def _set_model(self, model):
46
46
Resolve embedded model class once the field knows the model it belongs
47
47
to.
48
48
49
- If the model argument passed to __init__() was a string, resolve that
50
- string to the corresponding model class, similar to relation fields.
51
- However, we need to know our own model to generate a valid key
52
- for the embedded model class lookup and EmbeddedModelFields are
53
- not contributed_to_class if used in iterable fields. Thus the
54
- collection field sets this field's "model" attribute in its
55
- contribute_to_class().
49
+ If __init__()'s embedded_model argument is a string, resolve it to the
50
+ corresponding model class, similar to relation fields.
56
51
"""
57
52
self ._model = model
58
53
if model is not None and isinstance (self .embedded_model , str ):
@@ -69,8 +64,8 @@ def from_db_value(self, value, expression, connection):
69
64
70
65
def to_python (self , value ):
71
66
"""
72
- Passes embedded model fields' values through embedded fields
73
- to_python() and reinstiatates the embedded instance.
67
+ Pass embedded model fields' values through each field's to_python() and
68
+ reinstiatate the embedded instance.
74
69
"""
75
70
if value is None :
76
71
return None
@@ -91,14 +86,8 @@ def to_python(self, value):
91
86
92
87
def get_db_prep_save (self , embedded_instance , connection ):
93
88
"""
94
- Apply pre_save() and get_db_prep_save() of embedded instance
95
- fields and passes a field => value mapping down to database
96
- type conversions.
97
-
98
- The embedded instance will be saved as a column => value dict, but
99
- because we need to apply database type conversions on embedded instance
100
- fields' values and for these we need to know fields those values come
101
- from, we need to entrust the database layer with creating the dict.
89
+ Apply pre_save() and get_db_prep_save() of embedded instance fields and
90
+ create the {field: value} dict to be saved.
102
91
"""
103
92
if embedded_instance is None :
104
93
return None
@@ -121,7 +110,7 @@ def get_db_prep_save(self, embedded_instance, connection):
121
110
continue
122
111
field_values [field .attname ] = value
123
112
# This instance will exist in the database soon.
124
- # TODO.XXX : Ensure that this doesn't cause race conditions.
113
+ # TODO: Ensure that this doesn't cause race conditions.
125
114
embedded_instance ._state .adding = False
126
115
return field_values
127
116
@@ -164,11 +153,10 @@ def preprocess_lhs(self, compiler, connection):
164
153
mql = previous .as_mql (compiler , connection )
165
154
return mql , key_transforms
166
155
167
-
168
- def key_transform (self , compiler , connection ):
169
- mql , key_transforms = self .preprocess_lhs (compiler , connection )
170
- transforms = "." .join (key_transforms )
171
- return f"{ mql } .{ transforms } "
156
+ def as_mql (self , compiler , connection ):
157
+ mql , key_transforms = self .preprocess_lhs (compiler , connection )
158
+ transforms = "." .join (key_transforms )
159
+ return f"{ mql } .{ transforms } "
172
160
173
161
174
162
class KeyTransformFactory :
@@ -177,7 +165,3 @@ def __init__(self, key_name):
177
165
178
166
def __call__ (self , * args , ** kwargs ):
179
167
return KeyTransform (self .key_name , * args , ** kwargs )
180
-
181
-
182
- def register_embedded_model_field ():
183
- KeyTransform .as_mql = key_transform
0 commit comments