ID | Headline |
---|
Simple columns might only need one model field to represent their data, even when marked up by a callback function. However, if a column actually represents more than one model field, the list of those fields can be given in place of a single field name.
" "
. The utility of this might be limited, but it's a reasonable default to give you a starting point. Compound columns should target fields, not merely foreign keys. For example, you might indeed want the unicode(entry.blog)
representation to appear in the marked-up column data, but be sure to target the specific fields on Blog
that are represented in that display.
Specifying all of the relevent fields in a compound column helps make searching and sorting more natural. Sorting a compound column is the same as giving the field list to a call to the queryset order_by()
method.
class CompoundColumnDatatableView(DatatableView): model = Entry datatable_options = { 'columns': [ 'id', ("Headline", ['headline', 'blog__name'], 'get_headline_data'), ], } def get_headline_data(self, instance, *args, **kwargs): return "%s (%s)" % (instance.headline, instance.blog.name)