File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -194,3 +194,11 @@ class MuseumExhibit(models.Model):
194
194
195
195
def __str__ (self ):
196
196
return self .exhibit_name
197
+
198
+
199
+ class Tour (models .Model ):
200
+ guide = models .CharField (max_length = 100 )
201
+ exhibit = models .ForeignKey (MuseumExhibit , on_delete = models .CASCADE )
202
+
203
+ def __str__ (self ):
204
+ return f"Tour by { self .guide } "
Original file line number Diff line number Diff line change 15
15
MuseumExhibit ,
16
16
RestorationRecord ,
17
17
Review ,
18
+ Tour ,
18
19
)
19
20
20
21
@@ -150,6 +151,9 @@ def setUpTestData(cls):
150
151
],
151
152
),
152
153
)
154
+ cls .egypt_tour = Tour .objects .create (guide = "Amira" , exhibit = cls .egypt )
155
+ cls .wonders_tour = Tour .objects .create (guide = "Carlos" , exhibit = cls .wonders )
156
+ cls .lost_tour = Tour .objects .create (guide = "Yelena" , exhibit = cls .lost_empires )
153
157
154
158
def test_filter_with_field (self ):
155
159
self .assertCountEqual (
@@ -296,6 +300,15 @@ def test_slice(self):
296
300
MuseumExhibit .objects .filter (sections__0_1__section_number = 2 ), [self .new_descoveries ]
297
301
)
298
302
303
+ def test_foreign_field_exact (self ):
304
+ qs = Tour .objects .filter (exhibit__sections__section_number = 1 )
305
+ self .assertCountEqual (qs , [self .egypt_tour , self .wonders_tour ])
306
+
307
+ def test_foreign_field_with_slice (self ):
308
+ # Only wonders exhibit has exactly two sections, and this slice matches first two
309
+ qs = Tour .objects .filter (exhibit__sections__0_2__section_number__all = [1 , 2 ])
310
+ self .assertEqual (list (qs ), [self .wonders_tour ])
311
+
299
312
300
313
@isolate_apps ("model_fields_" )
301
314
class CheckTests (SimpleTestCase ):
You can’t perform that action at this time.
0 commit comments