From 5434ce231d75004bdbe5cf2b7b24ce67a2a6e737 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Thu, 2 Jun 2011 16:18:47 +0000 Subject: Fixed #11868 - Multiple sort in admin changelist. Many thanks to bendavis78 for the initial patch, and for input from others. Also fixed #7309. If people were relying on the undocumented default ordering applied by the admin before, they will need to add 'ordering = ["-pk"]' to their ModelAdmin. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16316 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/admin_views/models.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tests/regressiontests/admin_views/models.py') diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index 854fb60e70..98873966eb 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -243,9 +243,6 @@ class Person(models.Model): def __unicode__(self): return self.name - class Meta: - ordering = ["id"] - class BasePersonModelFormSet(BaseModelFormSet): def clean(self): for person_dict in self.cleaned_data: @@ -259,13 +256,17 @@ class PersonAdmin(admin.ModelAdmin): list_editable = ('gender', 'alive') list_filter = ('gender',) search_fields = ('^name',) - ordering = ["id"] save_as = True def get_changelist_formset(self, request, **kwargs): return super(PersonAdmin, self).get_changelist_formset(request, formset=BasePersonModelFormSet, **kwargs) + def queryset(self, request): + # Order by a field that isn't in list display, to be able to test + # whether ordering is preserved. + return super(PersonAdmin, self).queryset(request).order_by('age') + class Persona(models.Model): """ @@ -357,6 +358,9 @@ class Media(models.Model): class Podcast(Media): release_date = models.DateField() + class Meta: + ordering = ('release_date',) # overridden in PodcastAdmin + class PodcastAdmin(admin.ModelAdmin): list_display = ('name', 'release_date') list_editable = ('release_date',) @@ -795,6 +799,7 @@ class StoryAdmin(admin.ModelAdmin): list_display_links = ('title',) # 'id' not in list_display_links list_editable = ('content', ) form = StoryForm + ordering = ["-pk"] class OtherStory(models.Model): title = models.CharField(max_length=100) @@ -804,6 +809,7 @@ class OtherStoryAdmin(admin.ModelAdmin): list_display = ('id', 'title', 'content') list_display_links = ('title', 'id') # 'id' in list_display_links list_editable = ('content', ) + ordering = ["-pk"] admin.site.register(Article, ArticleAdmin) admin.site.register(CustomArticle, CustomArticleAdmin) -- cgit v1.3