user19711010
user19711010

Reputation:

count all objects within a values_list Django

This is a follow up question to this

Django object has no attribute in a _set.filter

    @property
    def mathe2(self):
        return self.lehrertabelle_set.count()
    @property
    def mathe3(self):
        return self.lehrertabelle_set.values_list('Stundenanteil_bei_WE', flat=True)[0] + self.mathe2

I got so far that I can calculate that but I need everything within values_list counted together, pls tell me how, I have no clue

Upvotes: 0

Views: 41

Answers (1)

Bartosz Stasiak
Bartosz Stasiak

Reputation: 1632

You can use sum() to sum values in the list

 @property
def mathe3(self):
    return sum(self.lehrertabelle_set.values_list('Stundenanteil_bei_WE', flat=True)) + self.mathe2

Upvotes: 1

Related Questions