django-computed-property icon indicating copy to clipboard operation
django-computed-property copied to clipboard

Trigger re-save on related model updates

Open brechin opened this issue 7 years ago • 2 comments

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.

brechin avatar Feb 02 '18 23:02 brechin

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.

jerch avatar Apr 08 '18 19:04 jerch

@jerch Thanks, I will check it out!

brechin avatar Apr 09 '18 14:04 brechin