title: Catch IntegrityError in Django Admin
body: <p>Working with Django 1.4</p>
  
  <p>I would like to catch an Integrity Error when a user does enter a duplicate value. At this moment the application just shows the default Django error page. (debug = True)</p>
  
  <h3>model</h3>
  
  <pre><code>class Foo(models.Model):
      name = models.Charfield(max_length=100, unique=True)
      identifier = models.CharField(max_length=100, unique=True)
      parent = models.ForeignKey("self", related_name="children")
      bar = models.ForeignKey(Bar, related_name="foos")
  </code></pre>
  
  <h3>admin</h3>
  
  <pre><code>from django.core.exceptions import ValidationError
  from django.db import IntegrityError
  
  class FooAdmin(admin.ModelAdmin):
      form = FooForm
  
      search_fields = ['name']
      list_display = ['name']
  
      def save_model(self, request, obj, form, change):
          try:
              obj.save()
          except IntegrityError as e:
              raise ValidationError(e)
  </code></pre>
  
  <h3>form</h3>
  
  <pre><code>class FooForm(forms.ModelForm):
      def __init__(self, *args, **kwargs):
          super(FooForm, self).__init__(*args, **kwargs)
  
          if self.instance.pk:
              self.fields["parent"].queryset = Foo.objects.filter(bar=self.instance.bar)
  
      def clean(self):
          bar_identifier = self.cleaned_data.get("bar").identifier
  
          parent = self.cleaned_data.get("parent")
          if parent is not None:
              parent_bar_identifier = parent.bar.identifier
              if bar_identifier != parent_bar_identifier:
                  raise forms.ValidationError("Bar identifier should match parent Bar identifier")
  
          return self.cleaded_data
  </code></pre>
  
  <p>At this moment I get an error page showing a ValidationError instead of an IntegrityError. (Which makes perfect sense) </p>
  
  <p>How would I be able to properly catch the IntegrityError and show it at the top of the Django admin page?</p>
  
  <h1>Update</h1>
  
  <p>I noticed there was a form in there to check if <code>foo.parent.bar.identifier</code> matches <code>foo.bar.identifier</code>.<br>
  When I remove the form from the ViewAdmin the error handling works as expected.  </p>
  
  <p>So I guess the question here would be: How do I check if the parents match when saving the admin form?</p>