mirror of
https://github.com/django/django.git
synced 2025-03-13 10:50:55 +00:00
Fixed #26261 -- Fixed queryset crash when excluding reverse GenericRelation.
Thanks Amir Hadi for the report.
This commit is contained in:
parent
51faf4bd17
commit
04b15022e8
@ -461,7 +461,7 @@ class GenericRelation(ForeignObject):
|
|||||||
to_opts=opts,
|
to_opts=opts,
|
||||||
target_fields=(opts.pk,),
|
target_fields=(opts.pk,),
|
||||||
join_field=self,
|
join_field=self,
|
||||||
m2m=not self.unique,
|
m2m=False,
|
||||||
direct=False,
|
direct=False,
|
||||||
filtered_relation=filtered_relation,
|
filtered_relation=filtered_relation,
|
||||||
)
|
)
|
||||||
|
@ -308,3 +308,13 @@ class GenericRelationTests(TestCase):
|
|||||||
thing = HasLinkThing.objects.create()
|
thing = HasLinkThing.objects.create()
|
||||||
link = Link.objects.create(content_object=thing)
|
link = Link.objects.create(content_object=thing)
|
||||||
self.assertCountEqual(link.targets.all(), [thing])
|
self.assertCountEqual(link.targets.all(), [thing])
|
||||||
|
|
||||||
|
def test_generic_reverse_relation_exclude_filter(self):
|
||||||
|
place1 = Place.objects.create(name="Test Place 1")
|
||||||
|
place2 = Place.objects.create(name="Test Place 2")
|
||||||
|
Link.objects.create(content_object=place1)
|
||||||
|
link2 = Link.objects.create(content_object=place2)
|
||||||
|
qs = Link.objects.filter(~Q(places__name="Test Place 1"))
|
||||||
|
self.assertSequenceEqual(qs, [link2])
|
||||||
|
qs = Link.objects.exclude(places__name="Test Place 1")
|
||||||
|
self.assertSequenceEqual(qs, [link2])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user