class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
total = qty * cost
위의 total = qty * cost
은 어떻게 해결할 수 있습니까? 나는 그것이 오류를 일으킬 것이라는 것을 안다. 그러나 이것을 다루는 방법을 모른다.값이 다른 필드 값의 계산 인 필드 만들기
class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
total = qty * cost
위의 total = qty * cost
은 어떻게 해결할 수 있습니까? 나는 그것이 오류를 일으킬 것이라는 것을 안다. 그러나 이것을 다루는 방법을 모른다.값이 다른 필드 값의 계산 인 필드 만들기
class PO(models.Model)
qty = models.IntegerField(null=True)
cost = models.IntegerField(null=True)
@property
def total(self):
return self.qty * self.cost
당신은 total
property
필드를 만들 수 있습니다 참조 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)
@ ahsan의 대답이 정확히 무엇입니까? – Ahsan
total은 속성이 아니기 때문에 미묘하게 잘못되었습니다. – datashaman
@MarlinForbes 'total = property (_get_total) same'을'@ property'와 isnt하지 않습니까? [여기] (http://www.artima.com/weblogs/viewpost.jsp?thread=240808)를 확인하십시오. – agconti