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):
194194
195195 def __str__ (self ):
196196 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 1515 MuseumExhibit ,
1616 RestorationRecord ,
1717 Review ,
18+ Tour ,
1819)
1920
2021
@@ -150,6 +151,9 @@ def setUpTestData(cls):
150151 ],
151152 ),
152153 )
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 )
153157
154158 def test_filter_with_field (self ):
155159 self .assertCountEqual (
@@ -296,6 +300,15 @@ def test_slice(self):
296300 MuseumExhibit .objects .filter (sections__0_1__section_number = 2 ), [self .new_descoveries ]
297301 )
298302
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+
299312
300313@isolate_apps ("model_fields_" )
301314class CheckTests (SimpleTestCase ):
You can’t perform that action at this time.
0 commit comments