Opened 20 years ago
Closed 20 years ago
#570 closed defect (duplicate)
formfields.SelectField doesn't select correct value for ForeignKey
Description ¶
formfields.SelectField renders withou "selected" attribute set to the correct option. This happens because FormWrapper fetches 'data' for SelectField.render() by its field_name. However most of the times real data for the field is stored in form's dict under field_name+'_id' key.
This effectively breaks every form with the ForeignKey generated by generic view 'update_object' or with Manipulators as described in docs at http://www.djangoproject.com/documentation/forms/
Patch follows...
Change History (7)
by , 20 years ago
comment:1 by , 20 years ago
An afterthought: since db_column may be supplied for any field, not just ForeignKey it looks like we should always get data from dict by db_column instead of field_name... Or not?
comment:2 by , 20 years ago
Things appeard to be even worse... In model instance's dict ForeignKey name ends with '_id' but the name of corresponding <select> doesn't. But they supposed to be equal keywise...
Next patch changes <select> names to the '_id' form.
comment:4 by , 20 years ago
I've read through Robert's first patch and it looks like it fixes the problem. How this ticket should be resolved? Duplicate? Worksforme?
comment:5 by , 20 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
If the patch in #535 fixes this, let's mark this as a duplicate.
Patch