mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #27810 -- Allowed query expressions in admin_order_field.
This commit is contained in:
committed by
Tim Graham
parent
d368784bac
commit
e307ff29d2
@@ -1,3 +1,4 @@
|
||||
import datetime
|
||||
import os
|
||||
import tempfile
|
||||
from io import StringIO
|
||||
@@ -94,6 +95,7 @@ class ArticleAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
'content', 'date', callable_year, 'model_year', 'modeladmin_year',
|
||||
'model_year_reversed', 'section', lambda obj: obj.title,
|
||||
'order_by_expression',
|
||||
)
|
||||
list_editable = ('section',)
|
||||
list_filter = ('date', 'section')
|
||||
@@ -110,6 +112,12 @@ class ArticleAdmin(admin.ModelAdmin):
|
||||
})
|
||||
)
|
||||
|
||||
def order_by_expression(self, obj):
|
||||
return obj.model_year
|
||||
# This ordering isn't particularly useful but shows that expressions can
|
||||
# be used for admin_order_field.
|
||||
order_by_expression.admin_order_field = models.F('date') + datetime.timedelta(days=3)
|
||||
|
||||
def changelist_view(self, request):
|
||||
return super().changelist_view(request, extra_context={'extra_var': 'Hello!'})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user