diff --git a/django/db/models/base.py b/django/db/models/base.py index d92fcb893a..3c2147ba78 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -280,7 +280,8 @@ class ModelBase(type): ) else: 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) # Copy indexes so that index names are unique when models extend an diff --git a/docs/releases/2.1.1.txt b/docs/releases/2.1.1.txt index a6ed58a7bb..ca424f40df 100644 --- a/docs/releases/2.1.1.txt +++ b/docs/releases/2.1.1.txt @@ -28,3 +28,7 @@ Bugfixes * Fixed a regression where the admin change form crashed if the user doesn't have the 'add' permission to a model that uses ``TabularInline`` (: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`). diff --git a/tests/generic_relations_regress/models.py b/tests/generic_relations_regress/models.py index f9cdb1b549..06f5888fbe 100644 --- a/tests/generic_relations_regress/models.py +++ b/tests/generic_relations_regress/models.py @@ -158,7 +158,7 @@ class SpecialGenericRelation(GenericRelation): class HasLinks(models.Model): - links = SpecialGenericRelation(Link) + links = SpecialGenericRelation(Link, related_query_name='targets') class Meta: abstract = True diff --git a/tests/generic_relations_regress/tests.py b/tests/generic_relations_regress/tests.py index 769a64d0f1..fc7447fa51 100644 --- a/tests/generic_relations_regress/tests.py +++ b/tests/generic_relations_regress/tests.py @@ -273,3 +273,12 @@ class GenericRelationTests(TestCase): link = Link.objects.create(content_object=place) result = Link.objects.filter(places=place) 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])