Code

Ticket #15279: multiple_abstract_inheritance_r15458.diff

File multiple_abstract_inheritance_r15458.diff, 1.8 KB (added by melinath, 3 years ago)
Line 
1diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
2index fd0a295..6bfdefe 100644
3--- a/django/db/models/fields/__init__.py
4+++ b/django/db/models/fields/__init__.py
5@@ -234,6 +234,10 @@ class Field(object):
6     def contribute_to_class(self, cls, name):
7         self.set_attributes_from_name(name)
8         self.model = cls
9+        if not hasattr(self, "_declared_on_class"):
10+            self._declared_on_class = cls
11+        if not hasattr(self, "_first_concrete_class") and not cls._meta.abstract:
12+            self._first_concrete_class = cls
13         cls._meta.add_field(self)
14         if self.choices:
15             setattr(cls, 'get_%s_display' % self.name, curry(cls._get_FIELD_display, field=self))
16diff --git a/django/db/models/options.py b/django/db/models/options.py
17index 2f64c56..e6f286d 100644
18--- a/django/db/models/options.py
19+++ b/django/db/models/options.py
20@@ -152,7 +152,16 @@ class Options(object):
21         # Insert the given field in the order in which it was created, using
22         # the "creation_counter" attribute of the field.
23         # Move many-to-many related fields from self.fields into
24-        # self.many_to_many.
25+        # self.many_to_many. Ignore duplicate fields inherited from a
26+        # single abstract base class.
27+        try:
28+            f = self.get_field(field.name)
29+        except FieldDoesNotExist:
30+            pass
31+        else:
32+            if f._declared_on_class == field._declared_on_class and getattr(f, '_first_concrete_class', None) == getattr(field, '_first_concrete_class', None):
33+                return
34+
35         if field.rel and isinstance(field.rel, ManyToManyRel):
36             self.local_many_to_many.insert(bisect(self.local_many_to_many, field), field)
37             if hasattr(self, '_m2m_cache'):