Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18086 -- Restored '-pk' as the default order in the admin chan…

…gelist. This rectifies a slight change in behavior introduced in Django 1.4 and r17635.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17881 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a0b55f30a843a9ce12a907d65edcd479f5a5b1cb 1 parent 93d1fdb
@jphalip jphalip authored
View
2  django/contrib/admin/views/main.py
@@ -258,7 +258,7 @@ def get_ordering(self, request, queryset):
if not (set(ordering) & set(['pk', '-pk', pk_name, '-' + pk_name])):
# The two sets do not intersect, meaning the pk isn't present. So
# we add it.
- ordering.append('pk')
+ ordering.append('-pk')
return ordering
View
2  tests/regressiontests/admin_changelist/models.py
@@ -69,7 +69,7 @@ class UnorderedObject(models.Model):
class OrderedObjectManager(models.Manager):
def get_query_set(self):
- return super(OrderedObjectManager, self).get_query_set().order_by('-number')
+ return super(OrderedObjectManager, self).get_query_set().order_by('number')
class OrderedObject(models.Model):
"""
View
38 tests/regressiontests/admin_changelist/tests.py
@@ -446,35 +446,35 @@ def test_deterministic_order_for_unordered_model(self):
class UnorderedObjectAdmin(admin.ModelAdmin):
list_per_page = 10
- def check_results_order(reverse=False):
+ def check_results_order(ascending=False):
admin.site.register(UnorderedObject, UnorderedObjectAdmin)
model_admin = UnorderedObjectAdmin(UnorderedObject, admin.site)
- counter = 51 if reverse else 0
+ counter = 0 if ascending else 51
for page in range (0, 5):
request = self._mocked_authenticated_request('/unorderedobject/?p=%s' % page, superuser)
response = model_admin.changelist_view(request)
for result in response.context_data['cl'].result_list:
- counter += -1 if reverse else 1
+ counter += 1 if ascending else -1
self.assertEqual(result.id, counter)
admin.site.unregister(UnorderedObject)
- # When no order is defined at all, everything is ordered by 'pk'.
+ # When no order is defined at all, everything is ordered by '-pk'.
check_results_order()
# When an order field is defined but multiple records have the same
- # value for that field, make sure everything gets ordered by pk as well.
+ # value for that field, make sure everything gets ordered by -pk as well.
UnorderedObjectAdmin.ordering = ['bool']
check_results_order()
# When order fields are defined, including the pk itself, use them.
UnorderedObjectAdmin.ordering = ['bool', '-pk']
- check_results_order(reverse=True)
- UnorderedObjectAdmin.ordering = ['bool', 'pk']
check_results_order()
+ UnorderedObjectAdmin.ordering = ['bool', 'pk']
+ check_results_order(ascending=True)
UnorderedObjectAdmin.ordering = ['-id', 'bool']
- check_results_order(reverse=True)
- UnorderedObjectAdmin.ordering = ['id', 'bool']
check_results_order()
+ UnorderedObjectAdmin.ordering = ['id', 'bool']
+ check_results_order(ascending=True)
def test_deterministic_order_for_model_ordered_by_its_manager(self):
"""
@@ -491,32 +491,32 @@ def test_deterministic_order_for_model_ordered_by_its_manager(self):
class OrderedObjectAdmin(admin.ModelAdmin):
list_per_page = 10
- def check_results_order(reverse=False):
+ def check_results_order(ascending=False):
admin.site.register(OrderedObject, OrderedObjectAdmin)
model_admin = OrderedObjectAdmin(OrderedObject, admin.site)
- counter = 51 if reverse else 0
+ counter = 0 if ascending else 51
for page in range (0, 5):
request = self._mocked_authenticated_request('/orderedobject/?p=%s' % page, superuser)
response = model_admin.changelist_view(request)
for result in response.context_data['cl'].result_list:
- counter += -1 if reverse else 1
+ counter += 1 if ascending else -1
self.assertEqual(result.id, counter)
admin.site.unregister(OrderedObject)
- # When no order is defined at all, use the model's default ordering (i.e. '-number')
- check_results_order(reverse=True)
+ # When no order is defined at all, use the model's default ordering (i.e. 'number')
+ check_results_order(ascending=True)
# When an order field is defined but multiple records have the same
- # value for that field, make sure everything gets ordered by pk as well.
+ # value for that field, make sure everything gets ordered by -pk as well.
OrderedObjectAdmin.ordering = ['bool']
check_results_order()
# When order fields are defined, including the pk itself, use them.
OrderedObjectAdmin.ordering = ['bool', '-pk']
- check_results_order(reverse=True)
- OrderedObjectAdmin.ordering = ['bool', 'pk']
check_results_order()
+ OrderedObjectAdmin.ordering = ['bool', 'pk']
+ check_results_order(ascending=True)
OrderedObjectAdmin.ordering = ['-id', 'bool']
- check_results_order(reverse=True)
+ check_results_order()
OrderedObjectAdmin.ordering = ['id', 'bool']
- check_results_order()
+ check_results_order(ascending=True)
View
2  tests/regressiontests/admin_filters/tests.py
@@ -654,7 +654,7 @@ def test_fk_with_to_field(self):
# Make sure the correct queryset is returned
queryset = changelist.get_query_set(request)
- self.assertEqual(list(queryset), [john, jack])
+ self.assertEqual(list(queryset), [jack, john])
filterspec = changelist.get_filters(request)[0][-1]
self.assertEqual(force_unicode(filterspec.title), u'department')
View
8 tests/regressiontests/admin_views/tests.py
@@ -1894,13 +1894,13 @@ def test_list_editable_pagination(self):
UnorderedObject.objects.create(id=2, name='Unordered object #2')
UnorderedObject.objects.create(id=3, name='Unordered object #3')
response = self.client.get('/test_admin/admin/admin_views/unorderedobject/')
- self.assertContains(response, 'Unordered object #1')
+ self.assertContains(response, 'Unordered object #3')
self.assertContains(response, 'Unordered object #2')
- self.assertNotContains(response, 'Unordered object #3')
- response = self.client.get('/test_admin/admin/admin_views/unorderedobject/?p=1')
self.assertNotContains(response, 'Unordered object #1')
+ response = self.client.get('/test_admin/admin/admin_views/unorderedobject/?p=1')
+ self.assertNotContains(response, 'Unordered object #3')
self.assertNotContains(response, 'Unordered object #2')
- self.assertContains(response, 'Unordered object #3')
+ self.assertContains(response, 'Unordered object #1')
def test_list_editable_action_submit(self):
# List editable changes should not be executed if the action "Go" button is
Please sign in to comment.
Something went wrong with that request. Please try again.