On Tue, Apr 20, 2010 at 10:01 AM, victor <xur...@gmail.com> wrote: > i have a model and relative form as following: > class contactTitleForm(forms.ModelForm): > titleType = forms.ChoiceField(label=_('Title Type'), choices = > contact_property_type.items(), > widget=forms.Select(attrs={'class':'mustin {required:true}'})) > contact = forms.ModelChoiceField(label=_('Contact'), > queryset=contact.objects.exclude(status='Deleted'), > widget=forms.Select(attrs={'class':'mustin {required:true}'})) > company = forms.CharField(label=_('Company'), max_length=512, > required=False, > widget=forms.TextInput(attrs={'class':'{required:false}'})) > department = forms.CharField(label=_('Department'), > max_length=512, required=False, > widget=forms.TextInput(attrs={'class':'{required:false}'})) > title = forms.CharField(label=_('Title'), max_length=512, > required=False, > widget=forms.TextInput(attrs={'class':'{required:false}'})) > reportTo = forms.ModelChoiceField(label=_('Report To'), > queryset=contact.objects.exclude(status='Deleted'), required=False, > widget=forms.Select(attrs={'class':'{required:false}'})) > status = forms.BooleanField(label=_('Title Status'), initial=True, > widget=forms.HiddenInput(attrs={'class':'mustin {required:true}'})) > > class contactTitle(models.Model): > titleType = models.CharField(_('Title Type'), max_length=64, > db_index=True) > contact = models.ForeignKey(contact, related_name="pcontact") > company = models.CharField(_('Company'), max_length=512, > null=True, blank=True) > department = models.CharField(_('Department'), max_length=512, > null=True, blank=True) > title = models.CharField(_('Title'), max_length=512, null=True, > blank=True) > reportTo = models.ForeignKey('contact', related_name="rtcontact", > blank=True, null=True) > status = models.BooleanField(_('Title Status'), default=True) > > when runing,i got following error hint: > 'ModelChoiceField' object has no attribute 'objects' > can anyone tell me how to fix it? > thx. >
In your form you refer to a model called 'contact'. However, you also define a field called 'contact'. That overwrites the model reference, and so you get the error. Use CamelCase for class names and lower_case for variable names. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.