diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index b11f9d5..9d5c304 100644
a
|
b
|
class ChangeList(object):
|
258 | 258 | if not (set(ordering) & set(['pk', '-pk', pk_name, '-' + pk_name])): |
259 | 259 | # The two sets do not intersect, meaning the pk isn't present. So |
260 | 260 | # we add it. |
261 | | ordering.append('pk') |
| 261 | ordering.append('-pk') |
262 | 262 | |
263 | 263 | return ordering |
264 | 264 | |
diff --git a/tests/regressiontests/admin_changelist/models.py b/tests/regressiontests/admin_changelist/models.py
index 6c0b789..1c615ea 100644
a
|
b
|
class UnorderedObject(models.Model):
|
69 | 69 | |
70 | 70 | class OrderedObjectManager(models.Manager): |
71 | 71 | def get_query_set(self): |
72 | | return super(OrderedObjectManager, self).get_query_set().order_by('-number') |
| 72 | return super(OrderedObjectManager, self).get_query_set().order_by('number') |
73 | 73 | |
74 | 74 | class OrderedObject(models.Model): |
75 | 75 | """ |
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
index 7e4546e..f4cdbde 100644
a
|
b
|
class ChangeListTests(TestCase):
|
446 | 446 | class UnorderedObjectAdmin(admin.ModelAdmin): |
447 | 447 | list_per_page = 10 |
448 | 448 | |
449 | | def check_results_order(reverse=False): |
| 449 | def check_results_order(ascending=False): |
450 | 450 | admin.site.register(UnorderedObject, UnorderedObjectAdmin) |
451 | 451 | model_admin = UnorderedObjectAdmin(UnorderedObject, admin.site) |
452 | | counter = 51 if reverse else 0 |
| 452 | counter = 0 if ascending else 51 |
453 | 453 | for page in range (0, 5): |
454 | 454 | request = self._mocked_authenticated_request('/unorderedobject/?p=%s' % page, superuser) |
455 | 455 | response = model_admin.changelist_view(request) |
456 | 456 | for result in response.context_data['cl'].result_list: |
457 | | counter += -1 if reverse else 1 |
| 457 | counter += 1 if ascending else -1 |
458 | 458 | self.assertEqual(result.id, counter) |
459 | 459 | admin.site.unregister(UnorderedObject) |
460 | 460 | |
461 | | # When no order is defined at all, everything is ordered by 'pk'. |
| 461 | # When no order is defined at all, everything is ordered by '-pk'. |
462 | 462 | check_results_order() |
463 | 463 | |
464 | 464 | # When an order field is defined but multiple records have the same |
465 | | # value for that field, make sure everything gets ordered by pk as well. |
| 465 | # value for that field, make sure everything gets ordered by -pk as well. |
466 | 466 | UnorderedObjectAdmin.ordering = ['bool'] |
467 | 467 | check_results_order() |
468 | 468 | |
469 | 469 | # When order fields are defined, including the pk itself, use them. |
470 | 470 | UnorderedObjectAdmin.ordering = ['bool', '-pk'] |
471 | | check_results_order(reverse=True) |
472 | | UnorderedObjectAdmin.ordering = ['bool', 'pk'] |
473 | 471 | check_results_order() |
| 472 | UnorderedObjectAdmin.ordering = ['bool', 'pk'] |
| 473 | check_results_order(ascending=True) |
474 | 474 | UnorderedObjectAdmin.ordering = ['-id', 'bool'] |
475 | | check_results_order(reverse=True) |
476 | | UnorderedObjectAdmin.ordering = ['id', 'bool'] |
477 | 475 | check_results_order() |
| 476 | UnorderedObjectAdmin.ordering = ['id', 'bool'] |
| 477 | check_results_order(ascending=True) |
478 | 478 | |
479 | 479 | def test_deterministic_order_for_model_ordered_by_its_manager(self): |
480 | 480 | """ |
… |
… |
class ChangeListTests(TestCase):
|
491 | 491 | class OrderedObjectAdmin(admin.ModelAdmin): |
492 | 492 | list_per_page = 10 |
493 | 493 | |
494 | | def check_results_order(reverse=False): |
| 494 | def check_results_order(ascending=False): |
495 | 495 | admin.site.register(OrderedObject, OrderedObjectAdmin) |
496 | 496 | model_admin = OrderedObjectAdmin(OrderedObject, admin.site) |
497 | | counter = 51 if reverse else 0 |
| 497 | counter = 0 if ascending else 51 |
498 | 498 | for page in range (0, 5): |
499 | 499 | request = self._mocked_authenticated_request('/orderedobject/?p=%s' % page, superuser) |
500 | 500 | response = model_admin.changelist_view(request) |
501 | 501 | for result in response.context_data['cl'].result_list: |
502 | | counter += -1 if reverse else 1 |
| 502 | counter += 1 if ascending else -1 |
503 | 503 | self.assertEqual(result.id, counter) |
504 | 504 | admin.site.unregister(OrderedObject) |
505 | 505 | |
506 | | # When no order is defined at all, use the model's default ordering (i.e. '-number') |
507 | | check_results_order(reverse=True) |
| 506 | # When no order is defined at all, use the model's default ordering (i.e. 'number') |
| 507 | check_results_order(ascending=True) |
508 | 508 | |
509 | 509 | # When an order field is defined but multiple records have the same |
510 | | # value for that field, make sure everything gets ordered by pk as well. |
| 510 | # value for that field, make sure everything gets ordered by -pk as well. |
511 | 511 | OrderedObjectAdmin.ordering = ['bool'] |
512 | 512 | check_results_order() |
513 | 513 | |
514 | 514 | # When order fields are defined, including the pk itself, use them. |
515 | 515 | OrderedObjectAdmin.ordering = ['bool', '-pk'] |
516 | | check_results_order(reverse=True) |
517 | | OrderedObjectAdmin.ordering = ['bool', 'pk'] |
518 | 516 | check_results_order() |
| 517 | OrderedObjectAdmin.ordering = ['bool', 'pk'] |
| 518 | check_results_order(ascending=True) |
519 | 519 | OrderedObjectAdmin.ordering = ['-id', 'bool'] |
520 | | check_results_order(reverse=True) |
| 520 | check_results_order() |
521 | 521 | OrderedObjectAdmin.ordering = ['id', 'bool'] |
522 | | check_results_order() |
523 | | No newline at end of file |
| 522 | check_results_order(ascending=True) |
| 523 | No newline at end of file |
diff --git a/tests/regressiontests/admin_filters/tests.py b/tests/regressiontests/admin_filters/tests.py
index d87c447..e2a12c9 100644
a
|
b
|
class ListFiltersTests(TestCase):
|
654 | 654 | |
655 | 655 | # Make sure the correct queryset is returned |
656 | 656 | queryset = changelist.get_query_set(request) |
657 | | self.assertEqual(list(queryset), [john, jack]) |
| 657 | self.assertEqual(list(queryset), [jack, john]) |
658 | 658 | |
659 | 659 | filterspec = changelist.get_filters(request)[0][-1] |
660 | 660 | self.assertEqual(force_unicode(filterspec.title), u'department') |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 564e492..2a389fd 100644
a
|
b
|
class AdminViewListEditable(TestCase):
|
1894 | 1894 | UnorderedObject.objects.create(id=2, name='Unordered object #2') |
1895 | 1895 | UnorderedObject.objects.create(id=3, name='Unordered object #3') |
1896 | 1896 | response = self.client.get('/test_admin/admin/admin_views/unorderedobject/') |
1897 | | self.assertContains(response, 'Unordered object #1') |
| 1897 | self.assertContains(response, 'Unordered object #3') |
1898 | 1898 | self.assertContains(response, 'Unordered object #2') |
1899 | | self.assertNotContains(response, 'Unordered object #3') |
1900 | | response = self.client.get('/test_admin/admin/admin_views/unorderedobject/?p=1') |
1901 | 1899 | self.assertNotContains(response, 'Unordered object #1') |
| 1900 | response = self.client.get('/test_admin/admin/admin_views/unorderedobject/?p=1') |
| 1901 | self.assertNotContains(response, 'Unordered object #3') |
1902 | 1902 | self.assertNotContains(response, 'Unordered object #2') |
1903 | | self.assertContains(response, 'Unordered object #3') |
| 1903 | self.assertContains(response, 'Unordered object #1') |
1904 | 1904 | |
1905 | 1905 | def test_list_editable_action_submit(self): |
1906 | 1906 | # List editable changes should not be executed if the action "Go" button is |