[Django]-Django tables 2 – how do i change the queryset of the model i am displaying?

5👍

You can use the get_table_data() method to modify your queryset.

class ViewJob(LoginRequiredMixin, SingleTableView):

    def get_table_data(self):
        job_pk = self.request.GET.get('pk')
        if job_pk:
            return Job.objects.get(pk=job_pk)
        else:
            return Job.objects.all()

https://django-tables2.readthedocs.io/en/latest/pages/generic-mixins.html

👤Ben

Leave a comment