I've been stuck for a couple of hours, and can't figure out the correct way to do it. So basically I know that looping is not a really good practice, because if we would have a lot of users, the system would start time outing. So my idea is to pick the correct way to get the things that I need.
This is our core scheme:
I need to make this kind of 'table', and these are the things that I need:
This is the thing that will be displayed in our Front-End, so for now, I only need to collect the correct data and pass it into our FE. We use celery tasks, so the timing is always set (Mondays at 6 PM for ex.)
This is what I've tried so far..
for user in User.objects.all():
start_date = timezone.now() - timedelta(weeks=1)
# How to loop correctly over every user and check for invoices??
invoices = InvoiceItem.objects.select_related('invoice', 'invoice__operation_ptr_id')
# invoices[0].operation_ptr_id ???
The looping for user in User.objects.all()
should probably be replaced to annotate
. How can I make the relationship to get invoices, withdrawals, expenses?
from Django: Get each user Invoices, Expenses, Withdrawals. (ORM) relationship
No comments:
Post a Comment