Module Docs
- Filtered Model Formset Table views.md
re-useable integrations of FilterView, ModelFormsetView, and SingleTableMixin
- Purpose:
sef of abstract class-based views.md that provide a declarative syntax to hide the integration details
- Core Problem:
Filters, ModelFormsets, and Tables all need a queryset
in a F-MF-T view, they need to share the same queryset - getting the MRO right is essential!
Tables need special logic to render a formset, and need the formset available at construct any “extra” rows.
Formset data need to be the [paged] table_data. Chicken meet Egg.
- class fmft.views.BaseModelFormSetSingleTableMixin[source]
A version of SingleTableMixin that injects the formset into the view’s Table class, mixed with a BaseFormSetFactory that fetches formset from table rather than constructing one itself.
- construct_formset()[source]
Fake! don’t construct another formset, just use the one integrated with the table.
- formset_class
alias of
BaseModelFormSet
- get_formset_and_table()[source]
Table and formset need to be constructed together - formset needs table’s qs, table needs forms
- get_table_data()[source]
Override to use the view’s object_list, which we assume is available, from somewhere
- property the_formset
Critically, there may only be one formset built with data from the one table.
- property the_table
There should be only one table, one table to rule them all!
- class fmft.views.BaseModelFormSetView(**kwargs)[source]
A Base class that emulates formsets.ModelFormSetView, but without its request handlers
- formset_class
alias of
BaseModelFormSet
- class fmft.views.FilterViewMixin[source]
Logic factored out from BaseFilterView so it can be mixed in, e.g., with a modelformset view
- class fmft.views.FilteredModelFormsetTableView(**kwargs)[source]
The whole enchilada - A Filtered Model Formset View loaded into a table. Mix and match from above to get it all. How does it work: form defines which table fields are rendered as form fields, other table columns rendered as usual; ProcessFormsetView does the heavy lifting in post()
- class fmft.views.FilteredModelFormsetView(**kwargs)[source]
A Filtered Formset View. Not sure how useful this is without a Table, but hey, maybe you just love writing table template logic :-P Core Problem: - need filtered object_list to construct formset, but that logic is buried in
FilterView.get()
Solution: re-write .get() / .post() so the two views.md play nicely together, with formset.queryset=filterset.qs
How does it work: - FilterViewMixin.configure_filterset duplicates logic from BaseFilterView to
build_old the object_list
custom get(), post() mix that logic in with the get() / post() logic from ModelFormSetView to handle constructing, validating, and saving the modelformset
- class fmft.views.FilteredTableView(**kwargs)[source]
Too easy - this one is batteries included. Thanks django-tables2 and django-filters, you are awesome.
How does it work: - concrete view provides the base queryset - FilterView.get() sets self.object_list = a filtered version of the base queryset - SingleTableMixin looks for self.object_list, thus loading the filtered queryset - Template should render the filterset and the table (see template
filtered_table.html)
- class fmft.views.ModelFormsetTableView(**kwargs)[source]
A ModelFormset View loaded into a table. Mix-and-match form fields with non-form fields and customize layout in code instead of in template logic.
How does it work: - form defines which table fields are rendered as form fields, other table columns
rendered as usual;
ProcessFormsetView does the heavy lifting in post()