title: Validation of dependant inlines in django admin
body: <p>I am using Django 1.4 and I want to set validation rules that compare values of different inlines.</p>
  
  <p>I have three simple classes</p>
  
  <p>In models.py:</p>
  
  <pre><code>class Shopping(models.Model):
      shop_name = models.CharField(max_length=200)
  
  class Item(models.Model):
      item_name = models.CharField(max_length=200)
      cost = models.IntegerField()
      item_shop = models.ForeignKey(Shopping)
  
  class Buyer(models.Model):
      buyer_name = models.CharField(max_length=200)
      amount = models.IntegerField()
      buyer_shop = models.ForeignKey(Shopping)
  </code></pre>
  
  <p>In admin.py:</p>
  
  <pre><code>class ItemInline(admin.TabularInline):
      model = Item
  
  class BuyerInline(admin.TabularInline):
      model = Buyer
  
  class ShoppingAdmin(admin.ModelAdmin):
      inlines = (ItemInline, BuyerInline)
  </code></pre>
  
  <p>So for example it is possible to buy a bottle of rhum at 10$ and one of vodka at 8$. Mike pays 15$ and Tom pays 3$.</p>
  
  <p>The goal is to prevent the user from saving an instance with sums that don't match: what has been paid must be the same as the sum of the item costs (ie 10+8 = 15+3).</p>
  
  <p>I tried:</p>
  
  <ul>
  <li>raising ValidationError in the Shopping.clean method. But the inlines aren't updated yet in clean so the sums are not correct</li>
  <li>raising ValidationError in the ShoppingAdmin.save_related method. But raising ValidationError here gives a very user unfriendly error page instead of redirecting to the change page with a nice error message.</li>
  </ul>
  
  <p>Is there any solution to this problem? Is client-side (javascript/ajax) validation the most simple?</p>