diff options
| author | René Fleschenberg <rene@fleschenberg.net> | 2015-11-07 21:50:40 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-14 17:40:08 -0500 |
| commit | 85b56b8f66664e60cfb3c3879f5772dedb3e8b1f (patch) | |
| tree | 7c3ae620830e7c7df7bd6af9d8201b08ba0a7fde /docs/ref/contrib/admin | |
| parent | f0fe86feaae49ffc7ad3f375c11bdf648a25d25b (diff) | |
[1.9.x] Fixed #25531 -- Documented that admin_order_field supports lookups.
Backport of 2c727101113770d41e0907b333568bc2c25435e0 from master
Diffstat (limited to 'docs/ref/contrib/admin')
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 3cf8ae59c5..6fa34228f9 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -714,6 +714,22 @@ subclass:: colored_first_name.admin_order_field = '-first_name' + ``admin_order_field`` supports query lookups to sort by values on related + models. This example includes an "author first name" column in the list + display and allows sorting it by first name:: + + class Blog(models.Model): + title = models.CharField(max_length=255) + author = models.ForeignKey(Person, on_delete=models.CASCADE) + + class BlogAdmin(admin.ModelAdmin): + list_display = ('title', 'author', 'author_first_name') + + def author_first_name(self, obj): + return obj.author.first_name + + author_first_name.admin_order_field = 'author__first_name' + * 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 |
