Author: mtredinnick
Date: 2008-09-03 13:38:43 -0500 (Wed, 03 Sep 2008)
New Revision: 8932
Modified:
django/trunk/django/db/models/base.py
django/trunk/tests/regressiontests/model_inheritance_regress/models.py
Log:
Fixed #7588 -- Inherit fields from concrete ancestor classes via abstract base
classes. Based on a patch from emulbreh.
Modified: django/trunk/django/db/models/base.py
===================================================================
--- django/trunk/django/db/models/base.py 2008-09-03 18:05:43 UTC (rev
8931)
+++ django/trunk/django/db/models/base.py 2008-09-03 18:38:43 UTC (rev
8932)
@@ -94,8 +94,8 @@
new_class._meta.virtual_fields
field_names = set([f.name for f in new_fields])
- # Concrete classes...
if not base._meta.abstract:
+ # Concrete classes...
if base in o2o_map:
field = o2o_map[base]
field.primary_key = True
@@ -107,9 +107,11 @@
new_class.add_to_class(attr_name, field)
new_class._meta.parents[base] = field
- # .. and abstract ones.
else:
- # Check for clashes between locally declared fields and those
on the ABC.
+ # .. and abstract ones.
+
+ # Check for clashes between locally declared fields and those
+ # on the ABC.
parent_fields = base._meta.local_fields +
base._meta.local_many_to_many
for field in parent_fields:
if field.name in field_names:
@@ -119,6 +121,9 @@
(field.name, name, base.__name__))
new_class.add_to_class(field.name, copy.deepcopy(field))
+ # Pass any non-abstract parent classes onto child.
+ new_class._meta.parents.update(base._meta.parents)
+
# Inherit managers from the abstract base classes.
base_managers = base._meta.abstract_managers
base_managers.sort()
Modified: django/trunk/tests/regressiontests/model_inheritance_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/model_inheritance_regress/models.py
2008-09-03 18:05:43 UTC (rev 8931)
+++ django/trunk/tests/regressiontests/model_inheritance_regress/models.py
2008-09-03 18:38:43 UTC (rev 8932)
@@ -77,6 +77,16 @@
class M2MChild(M2MBase):
name = models.CharField(max_length=50)
+class Evaluation(Article):
+ quality = models.IntegerField()
+
+ class Meta:
+ abstract = True
+
+class QualityControl(Evaluation):
+ assignee = models.CharField(max_length=50)
+
+
__test__ = {'API_TESTS':"""
# Regression for #7350, #7202
# Check that when you create a Parent object with a specific reference to an
@@ -242,4 +252,9 @@
>>> M2MChild.objects.filter(articles__isnull=False)
[]
+# All fields from an ABC, including those inherited non-abstractly should be
+# available on child classes (#7588). Creating this instance should work
+# without error.
+>>> _ = QualityControl.objects.create(headline="Problems in Django",
pub_date=datetime.datetime.now(), quality=10, assignee="adrian")
+
"""}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---