Reputation: 1452
I'm looking for a way to parse the value of integerFields and returning the value.
scoreChans = models.IntegerField(0)
scoreChansSet = models.BooleanField(False)
scoreYatzy = models.IntegerField(0)
scoreYatzySet = models.BooleanField(False)
scoreTotal = scoreChans + scoreYatzy
But this gives: TypeError: unsupported operand type(s) for +: 'IntegerField' and 'IntegerField'
Is there a way the fetch the values from these fields?
Upvotes: 1
Views: 1591
Reputation: 35619
You can only fetch the values on an instantiated model.
I assume you want to have a computed property? Something like:
class MyModel(models.Model):
score_a = models.IntegerField()
score_b = models.IntegerField()
@property
def total_score(self):
return self.score_a + self.score_b
Upvotes: 1