Code

Opened 9 years ago

Closed 9 years ago

#570 closed defect (duplicate)

formfields.SelectField doesn't select correct value for ForeignKey

Reported by: Maniac <Maniac@…> Owned by: adrian
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: UI/UX:

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@…> 9 years ago.
Patch
570.2.diff (2.3 KB) - added by Maniac <Maniac@…> 9 years ago.
corrected patch, added '_id' to <select> names

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by Maniac <Maniac@…>

Patch

comment:1 Changed 9 years ago by Maniac <Maniac@…>

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 Changed 9 years ago by Maniac <Maniac@…>

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.

Changed 9 years ago by Maniac <Maniac@…>

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

comment:3 Changed 9 years ago by robert@…

This is fixed correctly as part of #535.

comment:4 Changed 9 years ago by Maniac <Maniac@…>

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 Changed 9 years ago by adrian

  • Resolution set to duplicate
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.