With a normal ModelAdmin class I can set the ordering with:
ordering = ("field_name",)
There seems to be no option to set ordering for InlineModelAdmin. Is there a way to get the inline elements to sort by a particular field?
When you add a calculated field Django doesn't know how to do a order_by , so it doesn't add sorting capability on that field. If you want to add sorting on a calculated field, you have to tell Django what to pass to order_by . You can do this by setting the admin_order_field attribute on the calculated field method.
django-inline-actions provides a handy templatetag render_inline_action_fields , which adds these information as hidden fields to a form. As the action does not know that an intermediate form is used, we have to include some special handling.
This works now so you can just do something like:
class MyModelInline(admin.TabularInline): model = MyModel ordering = ("field_name",)
There's actually a ticket for this, with a patch here: http://code.djangoproject.com/ticket/13862
Don't know if it actually works, though.
Update: The ticket is marked as fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With