Django 1.11
I have multiple models that have the same fields as status, for example repairOrder, statusUpdate which have an odometer field just as status does. When a user makes a new statusupdate or repairOrder I would like it to update certain fields within the status model as well. The way I see it there are four options
- overriding the save() method on statusupdate
- using signals
- custom model manager, which could query for related models and update fields
- a method on the model that would call the related model and update where I wanted it to.
I've removed some fields to make the example more simple.
class Status(models.Model):
odometer = models.IntegerField()
vehicle = models.ForeignKey(Vehicle, on_delete=models.CASCADE)
...
class statusUpdate(models.Model):
odometer = models.IntegerField()
vehicle = models.ForeignKey(Vehicle, on_delete=models.CASCADE)
...
When a user creates a new stautsUpdate, I would like the odometer on Status to be set aswell.
Q: What would be the Django way of updating a related model's fields?
EDIT: Edited alot of the question to clarify the issue