Home > Back-end >  count all objects within a values_list Django
count all objects within a values_list Django

Time:09-09

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

CodePudding user response:

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
  • Related