@@ -156,17 +156,19 @@ def formfield(self, **kwargs):
156
156
157
157
@EmbeddedModelField .register_lookup
158
158
class EMFExact (lookups .Exact ):
159
- def model_to_dict (self , instance ):
159
+ def model_to_dict (self , instance , connection ):
160
160
"""
161
161
Return a dict containing the data in a model instance, as well as a
162
162
dict containing the data for any embedded model fields.
163
163
"""
164
164
data = {}
165
165
emf_data = {}
166
166
for f in instance ._meta .concrete_fields :
167
- value = f .value_from_object (instance )
167
+ value = f .get_db_prep_value ( f . value_from_object (instance ), connection )
168
168
if isinstance (f , EmbeddedModelField ):
169
- emf_data [f .name ] = self .model_to_dict (value ) if value is not None else (None , {})
169
+ emf_data [f .name ] = (
170
+ self .model_to_dict (value , connection ) if value is not None else (None , {})
171
+ )
170
172
continue
171
173
# Unless explicitly set, primary keys aren't included in embedded
172
174
# models.
@@ -202,7 +204,7 @@ def as_mql(self, compiler, connection):
202
204
and isinstance (self .lhs .ref_field , EmbeddedModelField )
203
205
):
204
206
if isinstance (value , models .Model ):
205
- value , emf_data = self .model_to_dict (value )
207
+ value , emf_data = self .model_to_dict (value , connection )
206
208
# Get conditions for any nested EmbeddedModelFields.
207
209
conditions = self .get_conditions ({lhs_mql : (value , emf_data )})
208
210
return {"$and" : conditions }
0 commit comments