Re: Aggregation and following relationships backwards multiple levels

2017-02-01 Thread Patrick Joy
Hi, Thank you for your response, this works perfectly! Patrick On Thursday, February 2, 2017 at 4:07:21 AM UTC+11, pradam.programming wrote: > > Hi Patrick, > you can do like this: > def total(self): > return ContractItem.objects.filter(contract__subbudget__budge__in= >

Re: Aggregation and following relationships backwards multiple levels

2017-02-01 Thread pradam programmer
Hi Patrick, you can do like this: def total(self): return ContractItem.objects.filter(contract__subbudget__budge__in= self.budget_set.all()).aggregate(Sum('total'))['total__sum'] try like this..! On Wed, Feb 1, 2017 at 7:14 PM, Patrick Joy wrote: > Hi all, > >

Re: Aggregation and following relationships backwards multiple levels

2017-02-01 Thread pradam programmer
from django.db.models import Q def total(self): subbudgets = SubBudget.objects.filter() contracts = Contract.objects.filter(subbudget__in=subbudgets) return ContractItem.objects.filter(contract__subbudget__budget__in=self.budget_set.

Aggregation and following relationships backwards multiple levels

2017-02-01 Thread Patrick Joy
Hi all, Would appreciate some advice on this, I'm having trouble working out the best way to aggregate across multiple foreign key relationships. I have come up with the solution below however I'm not sure if this is the correct way to handle this situation. Any advice would be appreciated.