#17252: Multi-sort in admin does not respect initial admin_order_field
-------------------------------------+-------------------------------------
Reporter: sebastian | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: SVN
Severity: Normal | Resolution:
Keywords: multi-sort, admin, | Triage Stage: Accepted
ordering | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 1
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by julien):
* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Thanks for providing tests, this helps reproducing this issue quite
clearly.
However, I'm not entirely happy with the fix, in particular with the fact
that it makes the `ModelAdmin.ordering` option non explicit. For example
(based on your tests), to sort by a method called `some_order()`, you
have to set `ordering` to `('order',)`.
`ModelAdmin.ordering` currently only accepts actual model fields. I think
it should be modified to also accept any method/function as long as they
define a `admin_order_field` pointing to an actual model field. That way
one could explicitly do:
{{{#!python
class MyModel(Model):
foo = models.CharField()
class MyModelAdmin(ModelAdmin):
def bar(self, obj):
return obj.foo
bar.admin_order_field = 'foo'
list_display = ('bar',)
ordering = ('bar',) # <-- Can order by method 'bar'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17252#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.