Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading