Kaydet (Commit) b5c7cb4d authored tarafından Ramiro Morales's avatar Ramiro Morales Kaydeden (comit) Tim Graham

Fixed #29653 -- Fixed missing related_query_name reverse accessor if…

Fixed #29653 -- Fixed missing related_query_name reverse accessor if GenericRelation is declared on an abstract base model.

Regression in 4ab027b9.

Thanks Lauri Kainulainen for the report.
üst 64e1a271
...@@ -280,7 +280,8 @@ class ModelBase(type): ...@@ -280,7 +280,8 @@ class ModelBase(type):
) )
else: else:
field = copy.deepcopy(field) field = copy.deepcopy(field)
field.mti_inherited = True if not base._meta.abstract:
field.mti_inherited = True
new_class.add_to_class(field.name, field) new_class.add_to_class(field.name, field)
# Copy indexes so that index names are unique when models extend an # Copy indexes so that index names are unique when models extend an
......
...@@ -28,3 +28,7 @@ Bugfixes ...@@ -28,3 +28,7 @@ Bugfixes
* Fixed a regression where the admin change form crashed if the user doesn't * Fixed a regression where the admin change form crashed if the user doesn't
have the 'add' permission to a model that uses ``TabularInline`` have the 'add' permission to a model that uses ``TabularInline``
(:ticket:`29637`). (:ticket:`29637`).
* Fixed a regression where a ``related_query_name`` reverse accessor wasn't set
up when a ``GenericRelation`` is declared on an abstract base model
(:ticket:`29653`).
...@@ -158,7 +158,7 @@ class SpecialGenericRelation(GenericRelation): ...@@ -158,7 +158,7 @@ class SpecialGenericRelation(GenericRelation):
class HasLinks(models.Model): class HasLinks(models.Model):
links = SpecialGenericRelation(Link) links = SpecialGenericRelation(Link, related_query_name='targets')
class Meta: class Meta:
abstract = True abstract = True
......
...@@ -273,3 +273,12 @@ class GenericRelationTests(TestCase): ...@@ -273,3 +273,12 @@ class GenericRelationTests(TestCase):
link = Link.objects.create(content_object=place) link = Link.objects.create(content_object=place)
result = Link.objects.filter(places=place) result = Link.objects.filter(places=place)
self.assertCountEqual(result, [link]) self.assertCountEqual(result, [link])
def test_generic_reverse_relation_with_abc(self):
"""
The reverse generic relation accessor (targets) is created if the
GenericRelation comes from an abstract base model (HasLinks).
"""
thing = HasLinkThing.objects.create()
link = Link.objects.create(content_object=thing)
self.assertCountEqual(link.targets.all(), [thing])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment