1+ import django .db .models .base as base
12from django .db import NotSupportedError
3+ from django .db .models .constants import LOOKUP_SEP
24from django .db .models .fields .related_lookups import In , RelatedIn
35from django .db .models .lookups import (
46 BuiltinLookup ,
810 UUIDTextMixin ,
911)
1012
13+ from .fields import EmbeddedModelField
1114from .query_utils import process_lhs , process_rhs
1215
1316
@@ -121,6 +124,26 @@ def uuid_text_mixin(self, compiler, connection): # noqa: ARG001
121124 raise NotSupportedError ("Pattern lookups on UUIDField are not supported." )
122125
123126
127+ class Options (base .Options ):
128+ def get_field (self , field_name ):
129+ if LOOKUP_SEP in field_name :
130+ previous = self
131+ keys = field_name .split (LOOKUP_SEP )
132+ path = []
133+ for field in keys :
134+ field = base .Options .get_field (previous , field )
135+ if isinstance (field , EmbeddedModelField ):
136+ previous = field .embedded_model ._meta
137+ else :
138+ previous = field
139+ path .append (field .column )
140+ column = "." .join (path )
141+ embedded_column = field .clone ()
142+ embedded_column .column = column
143+ return embedded_column
144+ return super ().get_field (field_name )
145+
146+
124147def register_lookups ():
125148 BuiltinLookup .as_mql = builtin_lookup
126149 FieldGetDbPrepValueIterableMixin .resolve_expression_parameter = (
@@ -131,3 +154,4 @@ def register_lookups():
131154 IsNull .as_mql = is_null
132155 PatternLookup .prep_lookup_value_mongo = pattern_lookup_prep_lookup_value
133156 UUIDTextMixin .as_mql = uuid_text_mixin
157+ base .Options = Options
0 commit comments