Django

Code

Changeset 6239

Show
Ignore:
Timestamp:
09/14/07 17:41:09 (1 year ago)
Author:
jkocherhans
Message:

newforms-admin: Fixed a problem with [6232] where an exception was raised if ModelAdmin? didn't specify ordering. Also, fixed #4926.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/django/contrib/admin/options.py

    r6232 r6239  
    293293        admin site. 
    294294        """ 
    295         return self.model._default_manager.get_query_set().order_by(*self.ordering) 
     295        ordering = self.ordering or () # otherwise we might try to *None, which is bad ;) 
     296        return self.model._default_manager.get_query_set().order_by(*ordering) 
    296297 
    297298    def queryset_add(self, request): 
  • django/branches/newforms-admin/tests/regressiontests/admin_ordering/models.py

    r6232 r6239  
    2525>>> b3.save() 
    2626 
     27The default ordering should be by name, as specified in the inner Meta class. 
     28 
     29>>> ma = ModelAdmin(Band, None) 
     30>>> [b.name for b in ma.queryset(None)] 
     31[u'Aerosmith', u'Radiohead', u'Van Halen'] 
     32 
     33 
     34Let's use a custom ModelAdmin that changes the ordering, and make sure it 
     35actually changes. 
     36 
    2737>>> class BandAdmin(ModelAdmin): 
    2838...     ordering = ('rank',) # default ordering is ('name',) 
     
    3040 
    3141>>> ma = BandAdmin(Band, None) 
    32 >>> [b.name for b in Band.objects.all()] 
    33 [u'Aerosmith', u'Radiohead', u'Van Halen'] 
    34  
    3542>>> [b.name for b in ma.queryset(None)] 
    3643[u'Radiohead', u'Van Halen', u'Aerosmith']