#7217 closed (wontfix)
ModelForm save method should take an optional dictionary.
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | 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
The only time we use save(commit=False)
is when there are fields in the model that aren’t in the form. There are a lot of places where it looks like
form = SomeForm(request.POST) instance = form.save(commit=False) instance.other_field = "some value" instance.another_field = calulated_value() instance.save()
There are literally dozens of places where I have that, but no other places that use commit=False
. It would be better if there was a way to pass a dictionary of values like form.save(extra = {"other_field": "some value", "another_field": calculated_value()})
Change History (2)
comment:1 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
It took me a while to get back to my Django project, but you’re right, this is a much better way.
Note:
See TracTickets
for help on using tickets.
You can create your instance before passing it into a
ModelForm
. I use this method almost exclusively.