On Aug 3, 5:23 pm, Daniel Roseman <[email protected]> wrote:
> On Aug 3, 3:08 pm, dnedbaylo <[email protected]> wrote:
>
>
>
> > Hey All,
>
> > I have a model with unique field. Here is what i get when i try to
> > save record with not-unique field value:
>
> > >>> from psdj.ksel import models
> > >>> try:
>
> > ...   m = models.Keyword(phrase='insurance')
> > ...   m.save()
> > ... except models.Keyword.IntegrityError, e:
> > ...   print e
> > ...
> > Traceback (most recent call last):
> >   File "<console>", line 4, in <module>
> > AttributeError: type object 'Keyword' has no attribute
> > 'IntegrityError'
>
> > I use latest release of Django, it's 1.1.
>
> > So, the questions is, why is not IntegrityError an attribute of models
> > same way as DoesNotExist? Or do i do something wrong?
>
> > Thanks in advance,
> > Dmitry
>
> You need to import it:
> from django.db import IntegrityError
> --
> DR.

OK. Thanks.

I was thinking about a case where try clause contains couple of save()
calls of different models and each model has unique field. And there
is no way to catch specific to model IntegrityError,
you can catch only "general" IntegrityError not bound to specific
model...

--
Dmitry
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to