2014-04-06 2 views
0

나는 작은 프로젝트를 가지고 있으며 다음 문장을 얻지 못했습니다. 어떤 도움이라도 좋을 것입니다. 사용자 입력은 $ 값인 self.sale_head 일 수 있으며 $ 값이 추가되지 않는 경우 self.estimated_weight_hd이 총 무게를 얻는 데 사용되는 경우 아래 코드는 총 판매 가격으로 사용할 수있는 estimated_weight_total을 반환해야합니다. 모든 것은 내가 수동으로 estimated_weight_total을 추가 할 때 작동합니다. 나는 왜 길을 잃었 느냐.Django의 문장이 제대로 작동하지 않는 경우

def calc_estimated_weight_total(self): 
    if self.sale_head <= 0: 
     amount = (self.number * self.estimated_weight_hd) 
     return amount 

def save(self): 
    self.estimated_total_weight = self.calc_estimated_weight_total() 
    super(SaleNote, self).save() 

답변

0

self.sale_head > 0 아무 것도 반환하지 않으면 원하는 코드가 작동하지 않습니다. 귀하의 설명에서 귀하의 코드는 다음과 같아야합니다.

def calc_estimated_weight_total(self): 
    if self.sale_head <= 0: 
     amount = (self.number * self.estimated_weight_hd) 
     return amount 
    else: 
     return something_only_you_know 

def save(self): 
    self.estimated_total_weight = self.calc_estimated_weight_total() 
    super(SaleNote, self).save() 
관련 문제