Trigger re-save on related model updates
brechin opened this issue · comments
Jason Brechin commented
Sometimes you want to store data that's based on a related model.
e.g. if you have the following model:
class Driver(models.Model):
name = models.CharField(...)
vehicle = models.ForeignKey(Vehicle)
driver_bio = models.ComputedCharField(compute_from='vehicle_based_bio', ...)
def vehicle_based_bio(self):
return 'My name is {NAME} and I drive a {QUALITY} {COLOR} {MODEL}'.format(
NAME=self.name,
QUALITY=self.vehicle.quality,
COLOR=self.vehicle.color,
MODEL=self.vehicle.model
)
... it would be great if the Driver object could be updated when the Vehicle is modified.
jerch commented
I have implemented something similiar to your django app with updates across relations. You might want to have a look it here https://github.com/netzkolchose/django-computedfields.
Jason Brechin commented
@jerch Thanks, I will check it out!