Сумма модельных методов django - PullRequest
0 голосов
/ 19 июня 2020

Я пытаюсь получить сумму некоторых методов моей модели и отобразить их на странице результатов. Я не уверен, насколько возможно это сделать в моем views.py. При запуске сервера я получаю следующую ошибку.

Неподдерживаемые типы операндов для + 'method' и 'method'

  1. 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

1 Ответ

0 голосов
/ 19 июня 2020

вы пробовали это?

previous_implementation = scores.exist_score() + scores.accessibility_score() + scores.blacklist_score() + scores.grant_amount_score() + scores.estimatedAnnual_budget_score()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...