1
0
mirror of https://github.com/django/django.git synced 2025-07-05 10:19:20 +00:00

magic-removal: model inheirtance can now be more than 1 level deep.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2506 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans 2006-03-08 20:59:00 +00:00
parent 7df29c013e
commit 4b0fcefbc2
2 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import django.db.models.manipulators
import django.db.models.manager
from django.db.models.fields import AutoField, ImageField
from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist
from django.db.models.fields.related import OneToOne, ManyToOne
from django.db.models.related import RelatedObject
from django.db.models.query import orderlist2sql, delete_objects
@ -56,6 +56,10 @@ class ModelBase(type):
# Add Fields inherited from parents
for parent in new_class._meta.parents:
for field in parent._meta.fields:
# Only add parent fields if they aren't defined for this class.
try:
new_class._meta.get_field(field.name)
except FieldDoesNotExist:
field.contribute_to_class(new_class, field.name)
new_class._prepare()

View File

@ -19,9 +19,19 @@ class Restaurant(Place):
def __repr__(self):
return "%s the restaurant" % self.name
class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField()
def __repr__(self):
return "%s the italian restaurant" % self.name
API_TESTS = """
# Make sure Restaurant has the right fields in the right order.
>>> [f.name for f in Restaurant._meta.fields]
['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza']
# Make sure ItalianRestaurant has the right fields in the right order.
>>> [f.name for f in ItalianRestaurant._meta.fields]
['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza', 'serves_gnocchi']
"""