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
-~----------~----~----~----~------~----~------~--~---

Reply via email to