Code

Opened 3 years ago

Closed 3 years ago

#16289 closed New feature (duplicate)

Make FormSet and related classes declarable

Reported by: bpeschier 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

Description

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.

Attachments (0)

Change History (2)

comment:1 Changed 3 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 3 years ago by melinath

  • Keywords formset added
  • Resolution set to duplicate
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.