Answer the question
In order to leave comments, you need to log in
How to call a method on a linked table?
I have two models. user and:
class Partnership(models.Model):
class Meta:
verbose_name = _('partnership.model.verbose_name')
verbose_name_plural = _('partnership.model.verbose_name_plural')
# владелец записи
user = models.ForeignKey(User, verbose_name=_('partnership.model.user'))
def get_amount_total(self):
if self.transaction_set.filter(is_approved=True).count():
# получаем суммирование всех транзакций
data = self.transaction_set.filter(is_approved=True).aggregate(amount_total=models.Sum('amount'))
return data['amount_total']
else:
return 0
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question