@@ -156,17 +156,19 @@ def formfield(self, **kwargs):
156156
157157@EmbeddedModelField .register_lookup
158158class EMFExact (lookups .Exact ):
159- def model_to_dict (self , instance ):
159+ def model_to_dict (self , instance , connection ):
160160 """
161161 Return a dict containing the data in a model instance, as well as a
162162 dict containing the data for any embedded model fields.
163163 """
164164 data = {}
165165 emf_data = {}
166166 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 )
168168 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+ )
170172 continue
171173 # Unless explicitly set, primary keys aren't included in embedded
172174 # models.
@@ -202,7 +204,7 @@ def as_mql(self, compiler, connection):
202204 and isinstance (self .lhs .ref_field , EmbeddedModelField )
203205 ):
204206 if isinstance (value , models .Model ):
205- value , emf_data = self .model_to_dict (value )
207+ value , emf_data = self .model_to_dict (value , connection )
206208 # Get conditions for any nested EmbeddedModelFields.
207209 conditions = self .get_conditions ({lhs_mql : (value , emf_data )})
208210 return {"$and" : conditions }
0 commit comments