1

I wish to populate/ set the value of another model while saving a model using django's model admin.I am using model form. I am unable to override the save method for the model form to do this. Can I get some sample code for this. Django 1.3. Sample code is as below:

models.py:

class Customer(models.Model):
    name = models.CharField(max_length=100, unique=True)
    active = models.BooleanField()

class Branch(models.Model):
    customer = models.ForeignKey(Customer)
    name = models.CharField(max_length=100)

class Service(models.Model):
    branch = models.ForeignKey(Branch, blank=True, null=True)
    AMC_start_date 
    AMC_expiry_date 
    other fields...

In admin.py, while saving the service instance, on comparing the AMC expiry date with current date, I would like to set the value of customer status as active /not. How do I do it? I use a model form for ServiceForm.

user956424
  • 1,611
  • 2
  • 37
  • 67

0 Answers0