16👍
✅
class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
@property
def total(self):
return self.qty * self.cost
38👍
You can make total
a property
field, see the docs
class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
def _get_total(self):
"Returns the total"
return self.qty * self.cost
total = property(_get_total)
- [Django]-POST jQuery array to Django
- [Django]-Django apps aren't loaded yet when using asgi
- [Django]-Django.db.utils.ProgrammingError: relation "bot_trade" does not exist
Source:stackexchange.com