Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7588 -- Inherit fields from concrete ancestor classes via abst…

…ract base

classes. Based on a patch from emulbreh.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8932 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d88688014f7fca77fb18530d36dd77e10b4bcb82 1 parent 9a89d1e
Malcolm Tredinnick authored September 03, 2008
11  django/db/models/base.py
@@ -94,8 +94,8 @@ def __new__(cls, name, bases, attrs):
94 94
                          new_class._meta.virtual_fields
95 95
             field_names = set([f.name for f in new_fields])
96 96
 
97  
-            # Concrete classes...
98 97
             if not base._meta.abstract:
  98
+                # Concrete classes...
99 99
                 if base in o2o_map:
100 100
                     field = o2o_map[base]
101 101
                     field.primary_key = True
@@ -107,9 +107,11 @@ def __new__(cls, name, bases, attrs):
107 107
                     new_class.add_to_class(attr_name, field)
108 108
                 new_class._meta.parents[base] = field
109 109
 
110  
-            # .. and abstract ones.
111 110
             else:
112  
-                # Check for clashes between locally declared fields and those on the ABC.
  111
+                # .. and abstract ones.
  112
+
  113
+                # Check for clashes between locally declared fields and those
  114
+                # on the ABC.
113 115
                 parent_fields = base._meta.local_fields + base._meta.local_many_to_many
114 116
                 for field in parent_fields:
115 117
                     if field.name in field_names:
@@ -119,6 +121,9 @@ def __new__(cls, name, bases, attrs):
119 121
                                             (field.name, name, base.__name__))
120 122
                     new_class.add_to_class(field.name, copy.deepcopy(field))
121 123
 
  124
+                # Pass any non-abstract parent classes onto child.
  125
+                new_class._meta.parents.update(base._meta.parents)
  126
+
122 127
             # Inherit managers from the abstract base classes.
123 128
             base_managers = base._meta.abstract_managers
124 129
             base_managers.sort()
15  tests/regressiontests/model_inheritance_regress/models.py
@@ -77,6 +77,16 @@ class M2MBase(models.Model):
77 77
 class M2MChild(M2MBase):
78 78
     name = models.CharField(max_length=50)
79 79
 
  80
+class Evaluation(Article):
  81
+    quality = models.IntegerField()
  82
+
  83
+    class Meta:
  84
+        abstract = True
  85
+
  86
+class QualityControl(Evaluation):
  87
+    assignee = models.CharField(max_length=50)
  88
+
  89
+
80 90
 __test__ = {'API_TESTS':"""
81 91
 # Regression for #7350, #7202
82 92
 # Check that when you create a Parent object with a specific reference to an
@@ -242,4 +252,9 @@ class M2MChild(M2MBase):
242 252
 >>> M2MChild.objects.filter(articles__isnull=False)
243 253
 []
244 254
 
  255
+# All fields from an ABC, including those inherited non-abstractly should be
  256
+# available on child classes (#7588). Creating this instance should work
  257
+# without error.
  258
+>>> _ = QualityControl.objects.create(headline="Problems in Django", pub_date=datetime.datetime.now(), quality=10, assignee="adrian")
  259
+
245 260
 """}

0 notes on commit d886880

Please sign in to comment.
Something went wrong with that request. Please try again.