1
+ import django .db .models .base as base
1
2
from django .db import NotSupportedError
3
+ from django .db .models .constants import LOOKUP_SEP
2
4
from django .db .models .fields .related_lookups import In , RelatedIn
3
5
from django .db .models .lookups import (
4
6
BuiltinLookup ,
8
10
UUIDTextMixin ,
9
11
)
10
12
13
+ from .fields import EmbeddedModelField
11
14
from .query_utils import process_lhs , process_rhs
12
15
13
16
@@ -121,6 +124,26 @@ def uuid_text_mixin(self, compiler, connection): # noqa: ARG001
121
124
raise NotSupportedError ("Pattern lookups on UUIDField are not supported." )
122
125
123
126
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
+
124
147
def register_lookups ():
125
148
BuiltinLookup .as_mql = builtin_lookup
126
149
FieldGetDbPrepValueIterableMixin .resolve_expression_parameter = (
@@ -131,3 +154,4 @@ def register_lookups():
131
154
IsNull .as_mql = is_null
132
155
PatternLookup .prep_lookup_value_mongo = pattern_lookup_prep_lookup_value
133
156
UUIDTextMixin .as_mql = uuid_text_mixin
157
+ base .Options = Options
0 commit comments