Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms-admin: Fixed a problem with [6232] where an exception was ra…

…ised if ModelAdmin didn't specify ordering. Also, fixed #4926.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6239 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cead4bada947f163e928e5f41cedb5e22defb743 1 parent 5ec5814
Joseph Kocherhans authored September 14, 2007
3  django/contrib/admin/options.py
@@ -292,7 +292,8 @@ def queryset(self, request):
292 292
         Returns a QuerySet of all model instances that can be edited by the
293 293
         admin site.
294 294
         """
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)
296 297
 
297 298
     def queryset_add(self, request):
298 299
         """
13  tests/regressiontests/admin_ordering/models.py
@@ -24,14 +24,21 @@ class Meta:
24 24
 >>> b3 = Band(name='Van Halen', bio='', rank=2)
25 25
 >>> b3.save()
26 26
 
  27
+The 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
+
  34
+Let's use a custom ModelAdmin that changes the ordering, and make sure it
  35
+actually changes.
  36
+
27 37
 >>> class BandAdmin(ModelAdmin):
28 38
 ...     ordering = ('rank',) # default ordering is ('name',)
29 39
 ...
30 40
 
31 41
 >>> ma = BandAdmin(Band, None)
32  
->>> [b.name for b in Band.objects.all()]
33  
-[u'Aerosmith', u'Radiohead', u'Van Halen']
34  
-
35 42
 >>> [b.name for b in ma.queryset(None)]
36 43
 [u'Radiohead', u'Van Halen', u'Aerosmith']
37 44
 

0 notes on commit cead4ba

Please sign in to comment.
Something went wrong with that request. Please try again.