summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_views/models.py
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2011-06-02 16:18:47 +0000
committerLuke Plant <L.Plant.98@cantab.net>2011-06-02 16:18:47 +0000
commit5434ce231d75004bdbe5cf2b7b24ce67a2a6e737 (patch)
tree3e4943eff23623b97fb7423e119c4733eace8aaa /tests/regressiontests/admin_views/models.py
parent78b37975c9d9f331b9ea9fa609d0596ae30ab6b4 (diff)
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
Diffstat (limited to 'tests/regressiontests/admin_views/models.py')
-rw-r--r--tests/regressiontests/admin_views/models.py14
1 files changed, 10 insertions, 4 deletions
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)