Live demo

ID headline Blog name Blog ID pub date


Description

The standard "__" related field syntax is supported in the model field names for a column. The only limitation is that the field's pretty-name should be explicitly given.

Sorting, searching, and value callbacks work on these columns as well.

When a value callback is used on a column, it receives the row's instance, and various keyword arguments to give the callback some context about the value. Callbacks always receive an argument default_value, which is the value as fetched from the target field. You can leverage this to avoid recalculating the same value from attribute lookups in your callbacks.



Implementation in code

        
    class RelatedFieldsDatatableView(DatatableView):
        model = Entry
        datatable_options = {
            'columns': [
                'id',
                'headline',
                ("Blog name", 'blog__name'),
                ("Blog ID", 'blog__id'),
                'pub_date',
            ],
        }