how to capture the exception
hi
In my models save() method I want to check if an Article with same
name already exists.
class Article(Model):
name=models.CharField(max_length = 1024, unique = True)
def save(self):
self.name=self.name.strip()
if Article.objects.filter(name__iexact=self.name).count()!=0:
raise Exception('article with name %s already
exists'%self.name)
When I create an article thru a ModelForm and give an existing
article's name ,it raises an exception and causes 500 server error.I
want to catch this exception and display an error message instead of
letting the program crash.Can someone tell me how and where I can do
this?Should I do this in the view?
thanks
harry
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home