Thanks a bunch! I rewrote my app using the manipulators and such and
it cut out a ton of stuff I'd written!

I guess I should read through the docs a bit more often ;)

Clint

On 11/1/05, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
>
> On 11/1/05, Clint Ecker <[EMAIL PROTECTED]> wrote:
> > In my view, I do something similar to the following (instantate a new
> > Person, fill in the information from a form, and try to save it).  When
> > someone enters a forumsname that's already in the database, I'd like to
> > catch that, and act appropriately.  So initially, I didn't have a try/catch
> > block so I could see what the exception was.  It told me that it would be
> > throwing an "IntegrityError" so I modified my code to look like this:
> > [...]
> > When I try the above code, I get the following error:
> > NameError: global name 'IntegrityError' is not defined
>
> Two things here:
>
> First, you're getting "global name 'IntegrityError' is not defined"
> because IntegrityError isn't in the local namespace when you're
> catching it. You'll need to import it -- probably from psycopg:
>
>     from psycopg import IntegrityError
>
> Second, it's bad practice to wrap save() in try/except. The save()
> methods don't perform validation -- they expect data to be valid
> already. Use a manipulator to validate your data. (A manipulator
> encapulates validation and form display.) See the docs here:
> http://www.djangoproject.com/documentation/forms/#custom-forms-and-manipulators
>
> Adrian
>
> --
> Adrian Holovaty
> holovaty.com | djangoproject.com | chicagocrime.org
>

Reply via email to