Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions extra_views/formsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,6 @@ class ModelFormSetMixin(FormSetMixin, MultipleObjectMixin):
exclude = None
fields = None

def get_formset_kwargs(self):
"""
Returns the keyword arguments for instantiating the formset.
"""
kwargs = super().get_formset_kwargs()
kwargs["queryset"] = self.get_queryset()
return kwargs

def get_factory_kwargs(self):
"""
Returns the keyword arguments for calling the formset factory
Expand All @@ -155,6 +147,14 @@ def get_formset(self):
"""
return modelformset_factory(self.model, **self.get_factory_kwargs())

def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
formset_class = self.get_formset()
formset_kwargs = self.get_formset_kwargs()
formset_kwargs["queryset"] = context['object_list']
context['formset'] = formset_class(**formset_kwargs)
return context

def formset_valid(self, formset):
"""
If the formset is valid, save the associated models.
Expand Down