1
1
import operator
2
- from datetime import timedelta
2
+ from datetime import date , timedelta
3
3
4
4
from django .core .exceptions import FieldDoesNotExist , ValidationError
5
5
from django .db import connection , models
28
28
D ,
29
29
Data ,
30
30
E ,
31
+ ExhibitMeta ,
31
32
ExhibitSection ,
32
33
Holder ,
33
34
Library ,
34
35
Movie ,
35
36
MuseumExhibit ,
37
+ RestorationRecord ,
36
38
Review ,
37
39
)
38
40
from .utils import truncate_ms
@@ -197,6 +199,36 @@ def setUpTestData(cls):
197
199
exhibit_name = "New Discoveries" ,
198
200
sections = [ExhibitSection (section_number = 1 , artifacts = [])],
199
201
)
202
+ cls .lost_empires = MuseumExhibit .objects .create (
203
+ exhibit_name = "Lost Empires" ,
204
+ meta = ExhibitMeta (
205
+ curator_name = "Dr. Amina Hale" ,
206
+ artifacts = [
207
+ ArtifactDetail (
208
+ name = "Bronze Statue" ,
209
+ description = "Statue from the Hellenistic period." ,
210
+ metadata = {"origin" : "Pergamon" , "material" : "bronze" },
211
+ restorations = [
212
+ RestorationRecord (
213
+ date = date (1998 , 4 , 15 ),
214
+ description = "Removed oxidized layer." ,
215
+ restored_by = "Restoration Lab A" ,
216
+ ),
217
+ RestorationRecord (
218
+ date = date (2010 , 7 , 22 ),
219
+ description = "Reinforced the base structure." ,
220
+ restored_by = "Dr. Liu Cheng" ,
221
+ ),
222
+ ],
223
+ last_restoration = RestorationRecord (
224
+ date = date (2010 , 7 , 22 ),
225
+ description = "Reinforced the base structure." ,
226
+ restored_by = "Dr. Liu Cheng" ,
227
+ ),
228
+ )
229
+ ],
230
+ ),
231
+ )
200
232
201
233
def test_filter_with_field (self ):
202
234
self .assertCountEqual (
@@ -215,6 +247,14 @@ def test_filter_with_embeddedfield_path(self):
215
247
[self .egypt , self .wonders , self .new_descoveries ],
216
248
)
217
249
250
+ def test_filter_with_embeddedfield_array_path (self ):
251
+ self .assertCountEqual (
252
+ MuseumExhibit .objects .filter (
253
+ meta__artifacts__restorations__0__restored_by = "Restoration Lab A"
254
+ ),
255
+ [self .lost_empires ],
256
+ )
257
+
218
258
219
259
class QueryingTests (TestCase ):
220
260
@classmethod
0 commit comments