mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #27810 -- Allowed query expressions in admin_order_field.
This commit is contained in:
parent
d368784bac
commit
e307ff29d2
5 changed files with 59 additions and 1 deletions
|
@ -745,6 +745,24 @@ subclass::
|
|||
|
||||
author_first_name.admin_order_field = 'author__first_name'
|
||||
|
||||
:doc:`Query expressions </ref/models/expressions>` may be used in
|
||||
``admin_order_field``. For example::
|
||||
|
||||
from django.db.models import Value
|
||||
from django.db.models.functions import Concat
|
||||
|
||||
class Person(models.Model):
|
||||
first_name = models.CharField(max_length=50)
|
||||
last_name = models.CharField(max_length=50)
|
||||
|
||||
def full_name(self):
|
||||
return self.first_name + ' ' + self.last_name
|
||||
full_name.admin_order_field = Concat('first_name', Value(' '), 'last_name')
|
||||
|
||||
.. versionadded:: 2.1
|
||||
|
||||
Support for expressions in ``admin_order_field`` was added.
|
||||
|
||||
* Elements of ``list_display`` can also be properties. Please note however,
|
||||
that due to the way properties work in Python, setting
|
||||
``short_description`` on a property is only possible when using the
|
||||
|
|
|
@ -47,6 +47,9 @@ Minor features
|
|||
:meth:`.ModelAdmin.get_sortable_by` method allow limiting the columns that
|
||||
can be sorted in the change list page.
|
||||
|
||||
* The ``admin_order_field`` attribute for elements in
|
||||
:attr:`.ModelAdmin.list_display` may now be a query expression.
|
||||
|
||||
:mod:`django.contrib.admindocs`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue