#17845 closed New feature (invalid)
Provide a way for model formsets to know how many records will be created
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Forms | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This is a feature request - please provide an easy way for model formsets to know how many records will be created.
As an example, I'm trying to write a clean() method for an inlineformset that checks that the database will always contain at least one model row when saved. The information to do this doesn't seem to be available.
Change History (2)
comment:1 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
One (untested) possibility is:
def clean(self): super(BlaForm, self).clean() c = 0 for f in self.extra_forms: if f.has_changed() and not self._should_delete_form(f): c += 1
After that c should tell you how many objects will get created, see save_new_objects and save_existing_objects for more info.
Note:
See TracTickets
for help on using tickets.
Unfortunately, this isn't something you can know in
clean()
.The sequence is as follows:
clean()
, well, cleans data received from the browser,That's why it isn't possible to know how many records will be created until step 2. However, you could check
len(form.new_objects)
after saving.