#13942: ModelChoiceField fix to_field_name fix
---------------------------------+------------------------------------------
          Reporter:  edcrewe     |         Owner:  nobody          
            Status:  closed      |     Milestone:                  
         Component:  Forms       |       Version:  1.2             
        Resolution:  invalid     |      Keywords:  ModelChoiceField
             Stage:  Unreviewed  |     Has_patch:  0               
        Needs_docs:  0           |   Needs_tests:  0               
Needs_better_patch:  0           |  
---------------------------------+------------------------------------------
Changes (by SmileyChris):

  * status:  new => closed
  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0
  * has_patch:  1 => 0
  * resolution:  => invalid

Comment:

 Replying to [ticket:13942 edcrewe]:
 {{{
 > 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:</pre>
 > 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.
 }}}

 It's not at all clear what you are asking for here. I can't see what your
 code example is supposed to do.

 If you have a test case or can expand on what you are actually trying to
 achieve then feel free to reopen.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13942#comment:1>
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.

Reply via email to