Django

Code

Changeset 2506

Show
Ignore:
Timestamp:
03/08/06 14:59:00 (3 years ago)
Author:
jkocherhans
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/models/base.py

    r2487 r2506  
    11import django.db.models.manipulators 
    22import django.db.models.manager 
    3 from django.db.models.fields import AutoField, ImageField 
     3from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist 
    44from django.db.models.fields.related import OneToOne, ManyToOne 
    55from django.db.models.related import RelatedObject 
     
    5757        for parent in new_class._meta.parents: 
    5858            for field in parent._meta.fields: 
    59                 field.contribute_to_class(new_class, field.name) 
     59                # Only add parent fields if they aren't defined for this class. 
     60                try: 
     61                    new_class._meta.get_field(field.name) 
     62                except FieldDoesNotExist: 
     63                    field.contribute_to_class(new_class, field.name) 
    6064 
    6165        new_class._prepare() 
  • django/branches/magic-removal/tests/modeltests/model_inheritance/models.py

    r2504 r2506  
    2020        return "%s the restaurant" % self.name 
    2121 
     22class ItalianRestaurant(Restaurant): 
     23    serves_gnocchi = models.BooleanField() 
     24 
     25    def __repr__(self): 
     26        return "%s the italian restaurant" % self.name 
     27 
    2228API_TESTS = """ 
    2329# Make sure Restaurant has the right fields in the right order. 
     
    2531['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza'] 
    2632 
     33# Make sure ItalianRestaurant has the right fields in the right order. 
     34>>> [f.name for f in ItalianRestaurant._meta.fields] 
     35['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza', 'serves_gnocchi'] 
     36 
    2737"""