V
V
Vladislav Koval2021-05-21 21:27:25
Django
Vladislav Koval, 2021-05-21 21:27:25

How to unpaginate in a child class?

There is such a loop

class AbstractSearchView(ListView):
    paginate_by = 10
    template_name = ''
    search_form = None

    def get_filter_func(self):
        raise NotImplementedError

    def get_queryset(self) -> 'QuerySet[SomeRequest]':
        filter_func = self.get_filter_func()

        try:
            search_data = filter_func(self.request.GET)
        except Exception:
            search_data = {}

        return SomeRequest.objects.filter(
            **search_data
        ).order_by('-resident_id', '-created').distinct('resident_id')

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(**kwargs)
        context['form'] = self.search_form(self.request.GET)
        return context


You need to inherit from this class, but remove pagination. The banal method works, but I'm not sure of its correctness paginate_by = 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2021-05-21
@Mi11er

Well, inheritance of classes is what inheritance is for)
What is taken from the parent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question