Django

Code

Changeset 7143

Show
Ignore:
Timestamp:
02/21/08 22:58:53 (10 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Whilst writing a test to bullet-proof [7141], a bug showed up.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/options.py

    r7142 r7143  
    6060            del meta_attrs['__doc__'] 
    6161            for attr_name in DEFAULT_NAMES: 
    62                 setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) 
     62                if attr_name in meta_attrs: 
     63                    setattr(self, attr_name, meta_attrs.pop(attr_name)) 
     64                elif hasattr(self.meta, attr_name): 
     65                    setattr(self, attr_name, getattr(self.meta, attr_name)) 
    6366 
    6467            # unique_together can be either a tuple of tuples, or a single 
  • django/branches/queryset-refactor/tests/modeltests/model_inheritance/models.py

    r7142 r7143  
    4747    class Meta: 
    4848        abstract = True 
     49        ordering = ['-rating'] 
    4950 
    5051class Restaurant(Place, Rating): 
    5152    serves_hot_dogs = models.BooleanField() 
    5253    serves_pizza = models.BooleanField() 
     54 
     55    class Meta(Rating.Meta): 
     56        db_table = 'my_restaurant' 
    5357 
    5458    def __unicode__(self): 
     
    125129 
    126130# Test the constructor for ItalianRestaurant. 
    127 >>> ir = ItalianRestaurant(name='Ristorante Miron', address='1234 W. Elm', serves_hot_dogs=False, serves_pizza=False, serves_gnocchi=True
     131>>> ir = ItalianRestaurant(name='Ristorante Miron', address='1234 W. Elm', serves_hot_dogs=False, serves_pizza=False, serves_gnocchi=True, rating=4
    128132>>> ir.save() 
    129133 
     
    134138>>> [f.name for f in ItalianRestaurant._meta.fields] 
    135139['id', 'name', 'address', 'place_ptr', 'rating', 'serves_hot_dogs', 'serves_pizza', 'restaurant_ptr', 'serves_gnocchi'] 
     140>>> Restaurant._meta.ordering 
     141['-rating'] 
    136142 
    137143# Even though p.supplier for a Place 'p' (a parent of a Supplier), a Restaurant 
     
    199205 
    200206>>> Restaurant.objects.filter(provider__name__contains="Chickens") 
    201 [<Restaurant: Demon Dogs the restaurant>, <Restaurant: Ristorante Miron the restaurant>] 
     207[<Restaurant: Ristorante Miron the restaurant>, <Restaurant: Demon Dogs the restaurant>] 
    202208>>> ItalianRestaurant.objects.filter(provider__name__contains="Chickens") 
    203209[<ItalianRestaurant: Ristorante Miron the italian restaurant>]