Opened 5 years ago

Closed 5 years ago

#16289 closed New feature (duplicate)

Make FormSet and related classes declarable

Reported by: Bas Peschier Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: formset
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


FormSets are now created with factories, but similar to ModelForm, it is entirely possible to declare a custom F!ormSet; the only thing missing are the defaults on the base classes in the code.

The idea is that you should be able to do:

class MyFormSet(formsets.FormSet):
  can_delete = True
  form = MyForm
  extra = 3

This is similar how we now teach people how to use ModelForms and opens up possibilities to override/extend behaviour.

Change History (2)

comment:1 Changed 5 years ago by rasca

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

This would be very useful for a nicer implementation of the formset derived cbv #16256 .

The BaseInlineFormSet is the only tricky one with the _get_foreign_key() and the max_num override when fk.unique=True .

I'd also move the defaults (e.g. extra=3) to the BaseFormSet and make the factories only pass dict keys whose value isn't None to type().

comment:2 Changed 5 years ago by melinath

Keywords: formset added
Resolution: duplicate
Status: newclosed

Since it's clearly documented that FormSet can be subclassed, and behavior overridden, I'm going to assume that the OP is requesting better support of/docs for a class-based declaration with no use of formset_factory.

That sounds nice. I would like that.

This is related to #10403 but applies to all FormSets, not just ModelFormSets. Marking as duplicate with a note in the other ticket.

Note: See TracTickets for help on using tickets.
Back to Top