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
24
24
Author ,
25
25
Book ,
26
26
Data ,
27
+ ExhibitMeta ,
27
28
ExhibitSection ,
28
29
Holder ,
29
30
Library ,
30
31
Movie ,
31
32
MuseumExhibit ,
32
33
NestedData ,
34
+ RestorationRecord ,
33
35
Review ,
34
36
)
35
37
from .utils import truncate_ms
@@ -199,6 +201,36 @@ def setUpTestData(cls):
199
201
exhibit_name = "New Discoveries" ,
200
202
sections = [ExhibitSection (section_number = 1 , artifacts = [])],
201
203
)
204
+ cls .lost_empires = MuseumExhibit .objects .create (
205
+ exhibit_name = "Lost Empires" ,
206
+ meta = ExhibitMeta (
207
+ curator_name = "Dr. Amina Hale" ,
208
+ artifacts = [
209
+ ArtifactDetail (
210
+ name = "Bronze Statue" ,
211
+ description = "Statue from the Hellenistic period." ,
212
+ metadata = {"origin" : "Pergamon" , "material" : "bronze" },
213
+ restorations = [
214
+ RestorationRecord (
215
+ date = date (1998 , 4 , 15 ),
216
+ description = "Removed oxidized layer." ,
217
+ restored_by = "Restoration Lab A" ,
218
+ ),
219
+ RestorationRecord (
220
+ date = date (2010 , 7 , 22 ),
221
+ description = "Reinforced the base structure." ,
222
+ restored_by = "Dr. Liu Cheng" ,
223
+ ),
224
+ ],
225
+ last_restoration = RestorationRecord (
226
+ date = date (2010 , 7 , 22 ),
227
+ description = "Reinforced the base structure." ,
228
+ restored_by = "Dr. Liu Cheng" ,
229
+ ),
230
+ )
231
+ ],
232
+ ),
233
+ )
202
234
203
235
def test_filter_with_field (self ):
204
236
self .assertCountEqual (
@@ -217,6 +249,14 @@ def test_filter_with_embeddedfield_path(self):
217
249
[self .egypt , self .wonders , self .new_descoveries ],
218
250
)
219
251
252
+ def test_filter_with_embeddedfield_array_path (self ):
253
+ self .assertCountEqual (
254
+ MuseumExhibit .objects .filter (
255
+ meta__artifacts__restorations__0__restored_by = "Restoration Lab A"
256
+ ),
257
+ [self .lost_empires ],
258
+ )
259
+
220
260
221
261
class QueryingTests (TestCase ):
222
262
@classmethod
0 commit comments