AndrewIngram / django-extra-views

Django's class-based generic views are awesome, let's have more of them.
MIT License
1.38k stars 172 forks source link

Cannot paginate using `ModelFormSetView` #261

Open yannish8 opened 1 year ago

yannish8 commented 1 year ago

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

powderflask commented 1 year ago

@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?

sdolemelipone commented 1 year ago

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.

powderflask commented 1 year ago

@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.

powderflask commented 1 year ago

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/