On Wed, Feb 24, 2010 at 5:13 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> But anyway: you already specified the unique constraint in the 'name'
> field definition, so adding this code in your model save() method is
> just useless - the uniqueness constraint WILL be applied at the db
> level.
>
> > this causes 500 error,and causes the traceback displayed on
> > browser..how can I prevent this crash and give the user some useful
> > warning?
>
> Do the test in your ModelForm 'clean_name' method and raise a
> ValidationError there.
>

If the model field has been specified as unique then the default ModelForm
clean() processing should already be checking for uniqueness. It is
necessary to ensure that the superclass clean() is called from any form-wide
clean() override (as noted here:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-clean-method).
There should be no need to add unique checking to either the form clean
methods or the model save() override.

Karen

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

Reply via email to