Opened 18 years ago
Closed 18 years ago
#3263 closed defect (fixed)
[patch] ValueError on form.save() for form_for_model and form_for_instance with ManyToManyField
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | normal | Keywords: | newforms ManyToManyField |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
The database API wants a list of related object instances, not the list of primary key values supplied by clean_data (actually integers as unicode strings) when you .save() a form_for_model or form_for_instance instance.
ValueError at /edit/news/2/
objects to add() must be Audience instances
Request Method: POST
Request URL: [my url]
Exception Type: ValueError
Exception Value: objects to add() must be Audience instances
Exception Location: /usr/lib/python2.4/site-packages/django/db/models/fields/related.py in _add_items, line 327
here are the relevant bits of the models:
class News(models.Model):
audiences = models.ManyToManyField(Audience,filter_interface=models.HORIZONTAL)
class Audience(models.Model):
name = models.CharField(maxlength=64,unique=True,db_index=True)
Attachments (1)
Change History (6)
by , 18 years ago
Attachment: | newforms_models.diff added |
---|
comment:1 by , 18 years ago
Summary: | ValueError on form.save() for form_for_model and form_for_instance with ManyToManyField → [patch] ValueError on form.save() for form_for_model and form_for_instance with ManyToManyField |
---|
This is a suggestion that works for me since I am an impatient person (and I have Deadlines!).
I have only tested it in the case where the form_for_model or _instance is invoked on the model that contains the ManyToManyField, so I can't comment on whether it works in the backwards relation case.
I love the work you guys are doing and can't wait for 1.0!
comment:2 by , 18 years ago
I should have used "_default_manager" instead of "objects" in the new line 41 of the attached .diff
comment:4 by , 18 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Thanks for the initial patch, Jeff.
comment:5 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Suggested patch