我正在尝试获取一些模型方法的总和并将它们显示在结果页面上。我不确定在我的 views.py 中完成这项工作的可能性有多大。运行服务器时出现以下错误。
+ "方法">和"方法"不支持的操作数类型
- models.py
class Organization(ModelFieldRequiredMixin, models.Model):
exist = models.BooleanField(help_text='Does organization exist physically?')
blacklist = models.BooleanField(help_text='Has organization previously been blacklisted by a national authority, funder or fund manager?')
grant_amount = MoneyField(decimal_places=2, max_digits=12, help_text='Total amount of grant(s) from largest donor to organization ')
estimatedAnnual_budget = models.IntegerField(help_text='Estimated annual budget of the organization (inclusive of the largest funder), in US Dollars')
class Scores(ModelFieldRequiredMixin, models.Model):
organization = models.ForeignKey(Organization,on_delete=models.CASCADE)
score = models.DecimalField(max_digits=9, decimal_places=2)
# Section1 - ORGANIZATIONAL BACKGROUND
def exist_score(self):
if self.organization.exist == True:
self.score=0.1
return self.score #The higher score
else:
score=0.1
return self.score #The lower score
def accessibility_score(self):
if self.organization.accessibility == True:
self.score=5
return self.score
else:
score=0
return self.score
def blacklist_score(self):
if self.organization.blacklist == True:
self.score=0
return self.score
else:
score=0
return self.score
# Section2 - PREVIOUS GRANTS & PERFORMANCE
def grant_amount_score(self):
if self.organization.grant_amount >= 2000000:
self.score=3.5
return self.score
else:
score=0
return self.score
def estimatedAnnual_budget_score(self):
if self.organization.estimatedAnnual_budget == True:
self.score=2
return self.score
else:
score=0.1
return self.score
- Views.py
def results_view(request):
scores=Scores()
previous_implementation = scores.exist_score + scores.accessibility_score + scores.blacklist_score + scores.grant_amount_score + scores.estimatedAnnual_budget_score
你试过这个吗?
previous_implementation = scores.exist_score() + scores.accessibility_score() + scores.blacklist_score() + scores.grant_amount_score() + scores.estimatedAnnual_budget_score()