1👍
How about using the following structure:
class MyModel(models.Model):
A_Field=models.IntegerField()
B_Field=models.IntegerField()
C_Field=models.IntegerField(null=True, blank=True)#this is the generated field
def get_C(self):
return self.A_Field+self.B_Field
def save(self, force_insert=False, force_update=False):
self.C_Field=self.get_C()
super(MyModel, self).save(force_insert, force_update)
Assigning an already correct default value (e.g. default = get_C in the field definition) will fail as A_Field and B_Field will not have a value at the point it is invoked.If you need this to be immediately evaluated as soon as you change A and B in a form you will need to use JS to do this.
Source:stackexchange.com