Opened 19 years ago

Closed 19 years ago

#570 closed defect (duplicate)

formfields.SelectField doesn't select correct value for ForeignKey

Reported by: Maniac <Maniac@…> Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal 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

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...

Attachments (2)

570.diff (1.8 KB ) - added by Maniac <Maniac@…> 19 years ago.
Patch
570.2.diff (2.3 KB ) - added by Maniac <Maniac@…> 19 years ago.
corrected patch, added '_id' to <select> names

Download all attachments as: .zip

Change History (7)

by Maniac <Maniac@…>, 19 years ago

Attachment: 570.diff added

Patch

comment:1 by Maniac <Maniac@…>, 19 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 Maniac <Maniac@…>, 19 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.

by Maniac <Maniac@…>, 19 years ago

Attachment: 570.2.diff added

corrected patch, added '_id' to <select> names

comment:3 by robert@…, 19 years ago

This is fixed correctly as part of #535.

comment:4 by Maniac <Maniac@…>, 19 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 Adrian Holovaty, 19 years ago

Resolution: duplicate
Status: newclosed

If the patch in #535 fixes this, let's mark this as a duplicate.

Note: See TracTickets for help on using tickets.
Back to Top