-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle pagination in ModelFormSetMixin #238
base: master
Are you sure you want to change the base?
Conversation
Thanks for the contribution! Can you please explain what's the essence of the changes? What was missing for pagination to work? Is there a way to make those changes in a backwards-compatible way? |
Well I don't think it's possible cause def get_context_data(self, *, object_list=None, **kwargs):
"""Get the context for this view."""
queryset = object_list if object_list is not None else self.object_list
page_size = self.get_paginate_by(queryset)
context_object_name = self.get_context_object_name(queryset)
if page_size:
paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
context = {
'paginator': paginator,
'page_obj': page,
'is_paginated': is_paginated,
'object_list': queryset
}
else:
context = {
'paginator': None,
'page_obj': None,
'is_paginated': False,
'object_list': queryset
}
if context_object_name is not None:
context[context_object_name] = queryset
context.update(kwargs)
return super().get_context_data(**context)
def get(self, request, *args, **kwargs):
filterset_class = self.get_filterset_class()
self.filterset = self.get_filterset(filterset_class)
if not self.filterset.is_bound or self.filterset.is_valid() or not self.get_strict():
self.object_list = self.filterset.qs
else:
self.object_list = self.filterset.queryset.none()
context = self.get_context_data(filter=self.filterset,
object_list=self.object_list)
return self.render_to_response(context) That's why filtered data can be also paginated. |
Codecov Report
@@ Coverage Diff @@
## master #238 +/- ##
==========================================
+ Coverage 88.77% 88.84% +0.06%
==========================================
Files 6 6
Lines 490 493 +3
Branches 54 54
==========================================
+ Hits 435 438 +3
Misses 40 40
Partials 15 15
Continue to review full report at Codecov.
|
I'm sorry, I still lack a lot of context. I have to say that it's been a long time since I've really worked on the code base so I'm not familiar with it anymore. I'm pretty sure that the patch is breaking backwards compatibility even if the tests don't cover it. |
Actually I only removed |
At the very least we'd need to have a deprecation path for the removed |
Please review the code once more, only thing changed is that |
What if someone called |
Changing this package to better integrate with
|
It's now even able to handle filtering with
django-filter
: