#10069: 'RelatedObject' object has no attribute 'unique' thrown by ModelForm
validation
----------------------+-----------------------------------------------------
 Reporter:  kmtracey  |       Owner:  nobody    
   Status:  new       |   Milestone:            
Component:  Forms     |     Version:  1.0       
 Keywords:            |       Stage:  Unreviewed
Has_patch:  0         |  
----------------------+-----------------------------------------------------
 Reported here: http://groups.google.com/group/django-
 users/browse_thread/thread/210298adf4a0f280

 More easily recreatable by creating a !ModelForm for the tutorial Poll
 model that looks like this:

 {{{
 #!python
 class PollForm(forms.ModelForm):
     choice = forms.CharField(required=False)
     class Meta:
         model = Poll
         exclude = ('pub_date',)
 }}}

 and then from `manage.py shell`:

 {{{
 >>> from polls.models import Poll, PollForm
 >>> pf = PollForm(data={'question': "Where's the beef?"})
 >>> pf.is_valid()
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/home/kmt/tmp/django/trunk/django/forms/forms.py", line 120, in
 is_valid
     return self.is_bound and not bool(self.errors)
   File "/home/kmt/tmp/django/trunk/django/forms/forms.py", line 111, in
 _get_errors
     self.full_clean()
   File "/home/kmt/tmp/django/trunk/django/forms/forms.py", line 241, in
 full_clean
     self.cleaned_data = self.clean()
   File "/home/kmt/tmp/django/trunk/django/forms/models.py", line 223, in
 clean
     self.validate_unique()
   File "/home/kmt/tmp/django/trunk/django/forms/models.py", line 251, in
 validate_unique
     if f.unique and self.cleaned_data.get(name) is not None:
 AttributeError: 'RelatedObject' object has no attribute 'unique'

 }}}

 Problem is the added 'choice' field on the form is not actually a Poll
 model field, but is findable via Poll's _meta.get_field_by_name due to the
 Choice model having a !ForeinKey pointing to Poll.  Fix is simple, I
 think, but I'm creating the ticket so someone searching on the problem in
 the future might find that it once existed and when it was fixed.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10069>
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