mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #9053 -- Allowed for sorting of callable and ModelAdmin methods specified in list_display (added in r8352). Previously attempting to sort on the former would raise an exception and the latter simply didn't sort. Also added tests for this function. Thanks rgl and jenan.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9211 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -19,12 +19,20 @@ class Article(models.Model):
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
def model_year(self):
|
||||
return self.date.year
|
||||
model_year.admin_order_field = 'date'
|
||||
|
||||
def callable_year(dt_value):
|
||||
return dt_value.year
|
||||
callable_year.admin_order_field = 'date'
|
||||
|
||||
class ArticleInline(admin.TabularInline):
|
||||
model = Article
|
||||
|
||||
class ArticleAdmin(admin.ModelAdmin):
|
||||
list_display = ('content', 'date')
|
||||
list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year')
|
||||
list_filter = ('date',)
|
||||
|
||||
def changelist_view(self, request):
|
||||
@@ -34,6 +42,10 @@ class ArticleAdmin(admin.ModelAdmin):
|
||||
'extra_var': 'Hello!'
|
||||
}
|
||||
)
|
||||
|
||||
def modeladmin_year(self, obj):
|
||||
return obj.date.year
|
||||
modeladmin_year.admin_order_field = 'date'
|
||||
|
||||
class CustomArticle(models.Model):
|
||||
content = models.TextField()
|
||||
|
||||
Reference in New Issue
Block a user