#19719 closed Bug (fixed)
Example in documentation saves an unbounded form
Reported by: | alexpirine | Owned by: | anonymous |
---|---|---|---|
Component: | Documentation | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
This doesn't work:
>>> a = Article.objects.get(pk=1) >>> f = ArticleForm(instance=a) >>> f.save() # AttributeError: 'Article' object has no attribute 'cleaned_data'
Also confirmed here:
http://stackoverflow.com/questions/2393348/django-form-error#comment2374980_2394120
and here:
https://docs.djangoproject.com/en/dev/ref/forms/api/#behavior-of-unbound-forms
Change History (7)
comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Bug |
comment:2 by , 12 years ago
comment:3 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
The issue here seems to be that whoever wrote the example assumed, reasonably enough perhaps, that "instance=a" binds the form. But it appears that the given instance and its fields are used only for supplying the "initial" parameter to the BaseForm class, whereas BaseForm.is_bound is based only on the presence of the "data" and "files" parameters. This is why, looking at the example above:
...would work, saving the passed data as a new Article and binding it to the form.