Live demo

blog headline Publication date Age


Description

This table actually uses the same column twice; the first time is for a raw display of the pub_date value, and the second is for a humanized version of the same information via the template filter timesince.

Note that the Age column is sortable using the underlying data from the pub_date field, and is not actually sorting the presentionally modified text of the frontend.

Callbacks should take the instance represented by the row, and *args and **kwargs to maximize flexibility with future data arguments sent by the callback dispatcher.



Implementation in code

        
    from django.template.defaultfilters import timesince
    class PresentationalChangesDatatableView(DatatableView):
        model = Entry
        datatable_options = {
            'columns': [
                'blog',
                'headline',
                ("Publication date", 'pub_date'),
                ("Age", 'pub_date', 'get_entry_age'),
            ],
        }

        def get_entry_age(self, instance, *args, **kwargs):
            return timesince(instance.pub_date)