{{{
my_model_admin.admin_order_field = F('field').desc(nulls_last=True)
}}}
or
{{{
@admin.display(ordering=F('field').desc(nulls_last=True))
}}}
but I can't any mention of it at
https://docs.djangoproject.com/en/4.2/ref/contrib/admin/.
In fact I had to find the original issue I report it to set this up
correctly.
Would it be possible to mention all possible values of
admin_order_field/ordering in the documentation?
--
Ticket URL: <https://code.djangoproject.com/ticket/34960>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* type: New feature => Cleanup/optimization
* resolution: => wontfix
Comment:
Thanks for the ticket. #30981 fixed a bug, not added a new feature. All
database expressions can be used in `ordering` and it's not an admin-
specific feature. Moreover, docs already explain how to sort `NULL`s in a
few places:
- https://docs.djangoproject.com/en/stable/ref/models/expressions/#using-f
-to-sort-null-values
-
https://docs.djangoproject.com/en/stable/ref/models/options/#django.db.models.Options.ordering
- https://docs.djangoproject.com/en/stable/ref/models/querysets/#order-by
some of them are reference in the Admin docs. I don't think it's worth
mentioning in the next place.
--
Ticket URL: <https://code.djangoproject.com/ticket/34960#comment:1>