I'm trying to work with django-datatables-view to add some basic filtering and sorting to my ListView.
I have a Result
model, which has a FK relationship to a Test
model. The Result
model has fields status
and when
, and the Test
has fields 'name', 'pass_percentage', and 'maintained' (these are the only fields I'm interested in displaying, both models have additional fields.
I have the following code:
class TestListJson(BaseDatatableView):
model = Result
columns = ['test__name', 'test__pass_percentage', 'test__maintained', 'status', 'when']
order_columns = ['test__name', 'test__pass_percentage', 'test__maintained', 'status', 'when']
def get_initial_queryset(self):
results = (
Result.objects.filter(
canonical=True, environment__config__in=['staging', 'production']
)
.select_related('test', 'environment')
.order_by('test__name', '-created_at')
.distinct('test__name')
.exclude(test__name__startswith='e2e')
)
#print (results.first()._meta.local_fields)
return results
But when I view the JSON endpoint, only the status
and when
fields have values. How should I be passing related model field names to columns
?