Problem with select fields and foreign keys
|Reported by:||hadsie@…||Owned by:||jacob|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I posted a similar message to this on the django users list a couple days ago but go no response, so it's possible this is actually a bug (not just a user error :)).
The problem is with values not getting saved in select fields. Specifically, select fields that are referencing an external type.
Say I have a model such as:
field1 = models.ForeignKey(Foo)
field2 = models.CharField(choices = (('1', 'first choice'), ('2', 'second
When I use a manipulator to build the form all goes smoothly. However, if I select a value for field1 on the form, but not field2 I'll get an error since field2 is required. But when this happens field1 gets reset, so the value isn't being saved. If I go the other way, and set field2, but not field1, I'll get an error message again but field2 will have its values preserved.
Looking into the django code a bit I narrowed down the issue to the django.oldforms.FormField.extract_data method. When it runs the line:
data = data_dict.get(self.get_member_name(), None)
The data for field1 won't be returned. I believe this is because the 'member_name' for field1 is field1_id, but the 'field_name' is field1.
Let me know if there's any other information I can provide.
Change History (7)
comment:1 Changed 9 years ago by ubernostrum
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 8 years ago by Gary Wilson <gary.wilson@…>
- Resolution set to worksforme
- Status changed from new to closed
comment:4 Changed 8 years ago by hadsie@…
- Resolution worksforme deleted
- Status changed from closed to reopened