How to use posgresql 'interval' in Django? How to use posgresql 'interval' in Django? postgresql postgresql

How to use posgresql 'interval' in Django?


You can try this to get the data within the past 12 months.

today= datetime.now()current_month_first_day = today.replace(day = 1)previous_month_last_day = current_month_first_day - timedelta(days = 1)past_12_month_first_day = previous_month_last_day - timedelta(days = 360)past_12_month_first_day = past_12_month_first_day.replace(day = 1) past_12_month_avg = Devc.objects.filter(date__range=(past_12_month_first_day,current_month_first_day)).aggregate(Sum('amount'))['amount']