Django Models: Aggregate Avg def objects

I am looking to calculate an average of the "percent" by "name", the origins of the mother on one side and the father on the other. I made my dictionnary, but maybe I'm using the AVG method wrong. Here is my code, I specify that name and percent are not in the database and cannot be in it.

    @property
    def mother_origines(self):
        if self.mother and self.mother.total_origines != 0:
            return self.mother.total_origines['name'], self.mother.total_origines['percent']
        else:
            return 0

    @property
    def father_origines(self):
        if self.father and self.father.total_origines != 0:
            return self.father.total_origines['name'], self.father.total_origines['percent']
        else:
            return 0

    @property
    def total_origines(self):
        if self.mother_origines != 0 and self.father_origines != 0:
            ori = self.mother.total_origines, self.father.total_origines
            return ori.aggregate(models.Avg('name'))
        if self.birth:
            return {'name':self.birth, 'percent':100.00} 
        else:
            return 0
Back to Top