Ordering by foreign key field
Issue #49
closed
Right now, if I order by a foreign key, the default behavior is that it sorts by the foreign key value. Is there a way to sort by a foreign key field?
For instance, if I click on a column named "User", it should filter by the user's name rather than it's pk.
Comments (3)
-
-
repo owner There is an order_columns parameter that you can use to define an ordering. As noted by @WheatleyNZL you can use dot notation to define columns. Alternatively, you can just override order_columns method.
-
repo owner - changed status to closed
- Log in to comment
What do you have in the columns property on your class view?
In the columns property you can use dot notation to access the foreign key fields.
E.g.
I don't think it is needed to answer your question but it might be relevant. You can sort by one attribute but display another by overriding the render_column(self, row, column). E.g. to display the username but sort by the pk