Opened 5 years ago
Closed 5 years ago
#31588 closed Cleanup/optimization (invalid)
Unclear behaviour for ModelForms
Reported by: | Vladislav | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 3.0 |
Severity: | Normal | Keywords: | forms |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I think it's very often task to add nessasary info to ModelForm before .save() and i suppose this must have official decision, not this workaround like answers in ticket:
https://stackoverflow.com/questions/17126983/add-data-to-modelform-object-before-saving
Note:
See TracTickets
for help on using tickets.
Hi. Thanks for the report.
The official decision, the recommended way of doing it is to call
save()
withcommit=False
, then make your modifications before saving the instance finally.This is documented in the save method docs. See the example there of modifying an author in this way.