Say we have a column like:
num_member = tables.Column(accessor = 'members.count', verbose_name = 'number of members' )
When I tried to sort this in the template, it raises:
Field Error: Cannot resolve keyword u'count' into field
I read the document and it says we can use order_by
by passing in some sort of accessor
, but how exactly do we do this please?
For function like Model's property method, you can access it directly using
accessor
. For example:Using the above method, you can show different kinds of data in table using accessor:
And accessor can be used for directly accessing related foreignkey model's field value like:
EDIT
Lets give an example of how
order_by
can be used:In the above code, what I have done is that, I am changing the order of the table data in context which will later be rendered in template.