﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10069	'RelatedObject' object has no attribute 'unique' thrown by ModelForm validation	Karen Tracey	Karen Tracey	"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."		closed	Forms	1.0		fixed			Accepted	0	0	0	0	0	0
