Django Models: Агрегировать объекты Avg def
Я хочу вычислить средний "процент" по "имени", происхождению матери с одной стороны и отца с другой. Я составил свой словарь, но, возможно, я неправильно использую метод AVG. Вот мой код, я указываю, что имени и процента нет и не может быть в базе данных.
@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