- changed status to invalid
Show values in cells which do not come from database fields
Sometimes I want to show computed values in tables. How can I do this with the djanog-datatables-view?
Comments (3)
-
repo owner -
render_column
sadly converts to string already so doing super() and then calling the method is result is callable is not possible. I'd insertif callable(value): value = value()
between the
getattr
andif value is None
. But I just noticed that there's also not yet an easy way to then define how search is handled for those fields. So I think I'll just stick to database fields for now.Would you be interested in the feature of having not only database fields as columns, but any callables/properties of models with support for search of those (via custom methods defined in the child of {{BaseDatatableView}}? I'm thinking about doing a PR.
-
repo owner Sorry, but I don't understand what you mean. You can use render_column like:
class MyClass(BaseDatatableView): def render_column(self, row, column): if column == 'mycolumn': return '{} and {}'.format(row.field1, row.get_field2_display()) #or compute value in any other way you want else: return super(MyClass, self).render_column(row, column)
Regarding filtering, just override filter_queryset method in a way you need.
- Log in to comment
Just override render_column or prepare_results method and render it as you want.