[Answered ]-Django- Staying DRY with multiple model methods

2👍

Why not just do:

class MyModel(models.Model):
    a = models.IntegerField(default=0)
    b = models.IntegerField(default=0)
    c = models.IntegerField(default=0)

    @property
    def x(self):
        return self.a + self.b

    @property
    def y(self):
        return self.x + self.c

    @property
    def z(self):
        return self.x + self.y

Leave a comment