1717from django_mongodb_backend .fields import EmbeddedModelField
1818from django_mongodb_backend .models import EmbeddedModel
1919
20- from .models import A , Address , Author , B , Book , C , D , Data , E , Holder , Library , Movie , Review
20+ from .models import (
21+ A ,
22+ Address ,
23+ ArtifactDetail ,
24+ Author ,
25+ B ,
26+ Book ,
27+ C ,
28+ D ,
29+ Data ,
30+ E ,
31+ ExhibitSection ,
32+ Holder ,
33+ Library ,
34+ Movie ,
35+ MuseumExhibit ,
36+ Review ,
37+ )
2138from .utils import truncate_ms
2239
2340
@@ -127,6 +144,59 @@ def setUpTestData(cls):
127144 Review (title = "Classic" , rating = 7 ),
128145 ]
129146 cls .bears = Movie .objects .create (title = "Bears" , reviews = reviews )
147+ cls .egypt = MuseumExhibit .objects .create (
148+ exhibit_name = "Ancient Egypt" ,
149+ sections = [
150+ ExhibitSection (
151+ section_number = 1 ,
152+ artifacts = [
153+ ArtifactDetail (
154+ name = "Ptolemaic Crown" ,
155+ description = "Royal headpiece worn by Ptolemy kings." ,
156+ metadata = {
157+ "material" : "gold" ,
158+ "origin" : "Egypt" ,
159+ "era" : "Ptolemaic Period" ,
160+ },
161+ )
162+ ],
163+ )
164+ ],
165+ )
166+ cls .wonders = MuseumExhibit .objects .create (
167+ exhibit_name = "Wonders of the Ancient World" ,
168+ sections = [
169+ ExhibitSection (
170+ section_number = 1 ,
171+ artifacts = [
172+ ArtifactDetail (
173+ name = "Statue of Zeus" ,
174+ description = "One of the Seven Wonders, created by Phidias." ,
175+ metadata = {"location" : "Olympia" , "height_m" : 12 },
176+ ),
177+ ArtifactDetail (
178+ name = "Hanging Gardens" ,
179+ description = "Legendary gardens of Babylon." ,
180+ metadata = {"debated_existence" : True },
181+ ),
182+ ],
183+ ),
184+ ExhibitSection (
185+ section_number = 2 ,
186+ artifacts = [
187+ ArtifactDetail (
188+ name = "Lighthouse of Alexandria" ,
189+ description = "Guided sailors safely to port." ,
190+ metadata = {"height_m" : 100 , "built" : "3rd century BC" },
191+ )
192+ ],
193+ ),
194+ ],
195+ )
196+ cls .new_descoveries = MuseumExhibit .objects .create (
197+ exhibit_name = "New Discoveries" ,
198+ sections = [ExhibitSection (section_number = 1 , artifacts = [])],
199+ )
130200
131201 def test_filter_with_field (self ):
132202 self .assertCountEqual (
@@ -139,6 +209,12 @@ def test_filter_with_model(self):
139209 [self .clouds , self .frozen ],
140210 )
141211
212+ def test_filter_with_embeddedfield_path (self ):
213+ self .assertCountEqual (
214+ MuseumExhibit .objects .filter (sections__0__section_number = 1 ),
215+ [self .egypt , self .wonders , self .new_descoveries ],
216+ )
217+
142218
143219class QueryingTests (TestCase ):
144220 @classmethod
0 commit comments