---begin code---
class Person(meta.Model):
fullname = meta.CharField(maxlength=100,verbose_name="Full Name",blank=False)
forumsname = meta.CharField(maxlength=100, blank=False, unique=True)
address1 = meta.CharField(maxlength=255, blank=False)
address2 = meta.CharField(maxlength=255)
city = meta.CharField(maxlength=255, blank=False)
stateprovince = meta.CharField(maxlength=100, blank=False)
postalcode = meta.CharField (maxlength=32, blank=False)
country = meta.CharField(maxlength=100, blank=False)
emailaddress = meta.EmailField(blank=False)
notes = meta.TextField()
beenemailed = meta.BooleanField(default=False)
randomkey = meta.CharField(maxlength=32)
...
--end code--
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:
---begin code---
p = persons.Person( fullname = input['fullname'],
forumsname = input['forumsname'].lower(),
address1 = input['address1'],
address2 = input['address2'],
city = input['city'],
stateprovince = input['stateprovince'],
country = input['country'],
notes = input['notes'],
postalcode = input['postalcode'],
emailaddress = input['emailaddress'],
randomkey = GenPasswd2(32) )
if errors == 0:
try:
p.save()
except IntegrityError, e: # this doesn't work!
errors = errors + 1
t['forumsnameerror'] = e
....
---end code---
When I try the above code, I get the following error:
NameError: global name 'IntegrityError' is not defined
So which is it? does it exist or not? I'm really confused here :)
Clint