@@ -46,13 +46,8 @@ def _set_model(self, model):
4646 Resolve embedded model class once the field knows the model it belongs
4747 to.
4848
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.
5651 """
5752 self ._model = model
5853 if model is not None and isinstance (self .embedded_model , str ):
@@ -69,8 +64,8 @@ def from_db_value(self, value, expression, connection):
6964
7065 def to_python (self , value ):
7166 """
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.
7469 """
7570 if value is None :
7671 return None
@@ -91,14 +86,8 @@ def to_python(self, value):
9186
9287 def get_db_prep_save (self , embedded_instance , connection ):
9388 """
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.
10291 """
10392 if embedded_instance is None :
10493 return None
@@ -121,7 +110,7 @@ def get_db_prep_save(self, embedded_instance, connection):
121110 continue
122111 field_values [field .attname ] = value
123112 # 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.
125114 embedded_instance ._state .adding = False
126115 return field_values
127116
@@ -164,11 +153,10 @@ def preprocess_lhs(self, compiler, connection):
164153 mql = previous .as_mql (compiler , connection )
165154 return mql , key_transforms
166155
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 } "
172160
173161
174162class KeyTransformFactory :
@@ -177,7 +165,3 @@ def __init__(self, key_name):
177165
178166 def __call__ (self , * args , ** kwargs ):
179167 return KeyTransform (self .key_name , * args , ** kwargs )
180-
181-
182- def register_embedded_model_field ():
183- KeyTransform .as_mql = key_transform
0 commit comments