You can override the clean method on the for and have it raise the
appropriate error for you. I've done the same thing before and came across
the issue that the form doesn't know the current user. I ended up adding a
user parameter to the init and passing it when I instantiated the form. Then
I made my clean_fieldname() method and checked for the record and raised
ValidationError if it existed.
You can find the docs at
http://docs.djangoproject.com/en/dev/ref/forms/validation/



On Sun, Mar 8, 2009 at 10:39 AM, ldm999 <malcolm.le...@gmail.com> wrote:

>
> I have a form tied to a List model where User and Name are
> unique_together.
>
> What's the best way to trap the IntegrityError if someone tries to
> create a new List with a User/Name combo that already exists?
>
> I know I could allow Django forms to do it if I include User in the
> form, but obviously I need User to be hidden and defaulted to the
> current user.
>
> TIA.
> >
>

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