1👍
You pass a date
object for today and yesterday. You can use a timedelta
object to obtain the day before:
from django.utils.timzone import now
from datetime import timedelta
cur_date=now().date()
today = Order.objects.filter(
created_at__date=cur_date
).aggregate(Sum('total_price'))
yesterday = Order.objects.filter(
created_at__date=cur_date-timedelta(days=1)
).aggregate(Sum('total_price'))
Source:stackexchange.com