First of all keep ur form in separate file named as forms.py .What all u r importing can u describe them .And check ur if condition. if desc and len(desc)>10: rasie ......
On Wed, Sep 16, 2009 at 3:57 PM, Anish <anishad...@gmail.com> wrote: > > Hi, > please check whether you import statement is this ---from django > import forms > > On Sep 16, 3:15 pm, "adee...@googlemail.com" <adee...@googlemail.com> > wrote: > > Hi Guys, > > > > I am quite new to Django, I'm having few problems with validation > > forms in Admin module, more specifically with raising exception in the > > ModelForm. I can validate and manipulate data in clean methods but > > cannot seem to raise any errors. Whenever I include any raise > > statement I get this error "'NoneType' object has no attribute > > 'ValidationError'". When I remove the raise part everything works > > fine. Any tips or suggestions on doing such a thing properly ? > > > > Here's an example of what I'm doing in Admin.py: > > > > ###admin.py#### > > > > class FontAdminForm(forms.ModelForm): > > # Import form from a model > > class Meta: > > model = Font > > > > def clean_name(self): > > return self.cleaned_data["name"].upper() > > > > # clean description. > > def clean_description(self): > > desc = self.cleaned_data['description'] > > if desc and if len(desc) < 10: > > raise forms.ValidationError('Description is too short.') > > return desc > > > > class FontAdmin(admin.ModelAdmin): > > form = FontAdminForm > > list_display = ['name', 'description'] > > > > admin.site.register(Font, FontAdmin) > > > > -- > > Thanks, > > Adnan > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---