#13942: ModelChoiceField fix to_field_name fix
------------------------------+---------------------------------------------
Reporter: edcrewe | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: 1.2
Keywords: ModelChoiceField | Stage: Unreviewed
Has_patch: 1 |
------------------------------+---------------------------------------------
line 989 in
http://code.djangoproject.com/browser/django/trunk/django/forms/models.py
ModelChoiceField
986 def to_python(self, value):
985 if value in EMPTY_VALUES:
986 return None
987 try:
988 key = self.to_field_name or 'pk'
989 value = self.queryset.get(**{key: value})
990 except self.queryset.model.DoesNotExist:
991 raise
ValidationError(self.error_messages['invalid_choice'])
992 return value
If you supply a to_field_name argument then the value that would be used
from that field name is replaced here.
Suggest replacing this with dummy object variable ...
989 object = self.queryset.get(**{key: value})
... so you get back the original field value, then this works for
generating choices with different option values to labels.
--
Ticket URL: <http://code.djangoproject.com/ticket/13942>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.