title: Django admin - How to calculate a field value depending on other model field values
body: <p>I have this scenario:
  A Service repair that might include repair/installation of multiple spare Parts in a machine. For every spare part involved in the service repair, the technician can select its state (new, used, refurbished). In a separate table called PartCostRate, I map a cost percentage for a state:</p>
  
  <p>models.py</p>
  
  <pre><code>class Part(models.Model):
      item_code = models.CharField(max_length=255, primary_key=True)
      name = models.CharField('Part Name', max_length=128)
      exw_price = models.DecimalField(max_digits=12, decimal_places=6)
  
  class PartCostRate(models.Model):
      PART_STATES = (
          ('N', 'New'),
          ('U', 'Used'),
          ('R', 'Refurbished'),
      )
      state = models.CharField(max_length=1, choices=Part_STATES)
      rate = models.DecimalField(max_digits=4, decimal_places=2)
  
  class Service(models.Model):
      service_code = models.CharField(max_length=10)
  
      parts = models.ManyToManyField(Part, through='ServicePart')
  
  class ServicePart(models.Model):
      PART_STATES = (
          ('N', 'New'),
          ('U', 'Used'),
          ('R', 'Refurbished'),
      )
      service = models.ForeignKey(Service)
      part = models.ForeignKey(Part)
      state = models.CharField(max_length=1, choices=PART_STATE)
      quantity = models.IntegerField()
      cost = models.DecimalField(max_digits=12, decimal_places=6)
  </code></pre>
  
  <p>admin.py</p>
  
  <pre><code>class ServicePartInline(admin.TabularInline):
      model = ServicePart
      extra = 1
      verbose_name = 'Repaired / Installed Part'
  
  class ServiceAdmin(admin.ModelAdmin):
     inlines = [ServicePartInline,]
  </code></pre>
  
  <p>From the admin interface, how can I calculate the cost of the part (from the inline of serviceadmin) depending on the selected state and quantity. For a select of Used, I need to query the PartCostRate model to check what is the rate of Used and then check the exw_price of that part and then do the calculation without forgetting the quantity.</p>
  
  <p>I am not sure how to do that from the admin. Does it require javascript in order to interactivley show the calculated cost in its field. Because sometimes they might change it manually.</p>
  
  <p>Thanks in advance</p>