django-extra-views
django-extra-views copied to clipboard
Cannot paginate using `ModelFormSetView`
The following code does not return 10 results as expected - all results from the model are returned instead. This is problematic when the table contains a lot of results:
class TestFormSetView(ModelFormSetView):
model = TestModel
fields = ["test_field"]
template_name = "test_output.html"
paginate_by = 10
I see that there is a PR open to handle pagination but it's from September 2021 and there's not been any activity on it for some time. I'm currently testing that PR locally but thought I'd create an issue to see if there are any alternatives
@AndrewIngram - I built a suite of CBVs on top of ModelFormSetView that integrate django-tables2 and django-filter. Includes a ModelFormsetTable view, FilteredModelFormset view, and FilteredModelFormsetTable view.
These views leave it to django-tables2 to handle pagination. They also greatly simplify (i.e. virtually eliminate) template logic for rendering such tabular formset views.
I'm considering options to release these and it makes sense to bundle them with django-extra-views, perhaps as a contrib package with a fmft (filtered-model-formset-table) module? Wondering if you'd be open to such a pull request, and if so if you have thoughts or preferences for the package structure?
Hi @powderflask, that does sound interesting although I'd be wary of making django-tables2 and django-filter dependencies of this package. Also it would increase the testing complexity as changes to those packages could break this one.
What if you added your code as a new section in the documentation for this project, rather than as a contrib package?
I use django-tables2
and django-filter
in combination like this too, I'd be interested to see how the pagination works.
@sdolemelipone that makes sense. Nice offer re: documentation, seems like a logical level to connect the 2 projects. Here's the Filtered-Model-Formset-Table views package: https://github.com/powderflask/django-fmft There's no docs yet - just doing the packaging and documentation now.
I'll propose a docs PR for extra-views
once I get my own FMFT docs in order. Maybe a new section after List Views named Integrations
, with a sub-section for Filtered Model Formset Table Views
?
re: pagination - it simply uses the tables2
paginated queryset as the formset data, otherwise lets tables2 handle pagination.
For anyone interested... Basic docs are up: https://django-fmft.readthedocs.io/en/latest/ And package is now on pipy: https://pypi.org/project/django-fmft/