#7006: Overridden fields/widgets for ForeignKeys in ModelForms
----------------------------------------------------------+-----------------
          Reporter:  Simon Litchfield <[EMAIL PROTECTED]>  |         Owner:  
msaelices
            Status:  closed                               |     Milestone:  1.0 
     
         Component:  Forms                                |       Version:  SVN 
     
        Resolution:  invalid                              |      Keywords:      
     
             Stage:  Accepted                             |     Has_patch:  0   
     
        Needs_docs:  0                                    |   Needs_tests:  0   
     
Needs_better_patch:  0                                    |  
----------------------------------------------------------+-----------------
Changes (by msaelices):

  * status:  assigned => closed
  * resolution:  => invalid

Comment:

 I think error is the normal behaviour here. Validation success because is
 a simple {{{CharField}}}, but when you save form,
 {{{form.cleaned_data['affiliate']}}} is {{{'1'}}} instead of a instance to
 {{{Affiliate}}}.

 This can be quickly done with this form (if you don't want to use other
 custom Field):
 {{{
 #!python
 class BookingForm(forms.ModelForm):
     affiliate = forms.CharField(max_length=20, required=False,
 label='Affiliate Code')

     class Meta:
         model = Booking
         fields = ('first_name', 'last_name', 'affiliate')

     def clean_affiliate(self):
         value = self.cleaned_data['affiliate']
         try:
             return Affiliate.objects.get(id=value)
         except Affiliate.DoesNotExist:
             raise ValidationError('Affiliate %s does not exist' % value)
 }}}

 I will mark this as ''invalid'', because I think behaviour is right.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/7006#comment:9>
Django Code <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