diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-22 04:58:53 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-22 04:58:53 +0000 |
| commit | 83e00a237158f7961b06abd31c2ed867f1831c3f (patch) | |
| tree | b93fcaf464b26b47f4c999814b960c7e993bb9fe | |
| parent | b7be3d63e36ee79db51dcabf0f210349e4d6f715 (diff) | |
queryset-refactor: Whilst writing a test to bullet-proof [7141], a bug showed up.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7143 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/options.py | 5 | ||||
| -rw-r--r-- | tests/modeltests/model_inheritance/models.py | 10 |
2 files changed, 12 insertions, 3 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index 7fa7fe0174..0796a3f7c9 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -59,7 +59,10 @@ class Options(object): del meta_attrs['__module__'] del meta_attrs['__doc__'] for attr_name in DEFAULT_NAMES: - setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) + if attr_name in meta_attrs: + setattr(self, attr_name, meta_attrs.pop(attr_name)) + elif hasattr(self.meta, attr_name): + setattr(self, attr_name, getattr(self.meta, attr_name)) # unique_together can be either a tuple of tuples, or a single # tuple of two strings. Normalize it to a tuple of tuples, so that diff --git a/tests/modeltests/model_inheritance/models.py b/tests/modeltests/model_inheritance/models.py index df0fb77ccb..95ff4b55f2 100644 --- a/tests/modeltests/model_inheritance/models.py +++ b/tests/modeltests/model_inheritance/models.py @@ -46,11 +46,15 @@ class Rating(models.Model): class Meta: abstract = True + ordering = ['-rating'] class Restaurant(Place, Rating): serves_hot_dogs = models.BooleanField() serves_pizza = models.BooleanField() + class Meta(Rating.Meta): + db_table = 'my_restaurant' + def __unicode__(self): return u"%s the restaurant" % self.name @@ -124,7 +128,7 @@ Test constructor for Restaurant. >>> r.save() # Test the constructor for ItalianRestaurant. ->>> ir = ItalianRestaurant(name='Ristorante Miron', address='1234 W. Elm', serves_hot_dogs=False, serves_pizza=False, serves_gnocchi=True) +>>> ir = ItalianRestaurant(name='Ristorante Miron', address='1234 W. Elm', serves_hot_dogs=False, serves_pizza=False, serves_gnocchi=True, rating=4) >>> ir.save() # Make sure Restaurant and ItalianRestaurant have the right fields in the right @@ -133,6 +137,8 @@ Test constructor for Restaurant. ['id', 'name', 'address', 'place_ptr', 'rating', 'serves_hot_dogs', 'serves_pizza'] >>> [f.name for f in ItalianRestaurant._meta.fields] ['id', 'name', 'address', 'place_ptr', 'rating', 'serves_hot_dogs', 'serves_pizza', 'restaurant_ptr', 'serves_gnocchi'] +>>> Restaurant._meta.ordering +['-rating'] # Even though p.supplier for a Place 'p' (a parent of a Supplier), a Restaurant # object cannot access that reverse relation, since it's not part of the @@ -198,7 +204,7 @@ DoesNotExist: Restaurant matching query does not exist. [<Supplier: Luigi's Pasta the supplier>, <Supplier: Joe's Chickens the supplier>] >>> Restaurant.objects.filter(provider__name__contains="Chickens") -[<Restaurant: Demon Dogs the restaurant>, <Restaurant: Ristorante Miron the restaurant>] +[<Restaurant: Ristorante Miron the restaurant>, <Restaurant: Demon Dogs the restaurant>] >>> ItalianRestaurant.objects.filter(provider__name__contains="Chickens") [<ItalianRestaurant: Ristorante Miron the italian restaurant>] |
