django queryset - Get the data particular to current year only

60 views
Skip to first unread message

Trippy Samurai

unread,
Mar 31, 2022, 1:51:59 AM3/31/22
to Django users

I have my query written to get some thing from database and display on my website that query is getting all the data from db but what if i want to get the data particular to current year only


def get(self, request, *args, **kwargs):
    filters = self.get_filters()

    result = Model.objects.all().filter(*filters).distinct().aggregate(
        t=Sum('t'),
        b=Sum('b'),
    )

    result2 = Model.objects.all().filter(*filters).distinct().aggregate(
        past_due=Sum('balance', filter=Q(due_date__lt=timezone.now()))
    )

    zero = Decimal('0.00')

    total = result['t'] or zero
    balance = result['b'] or zero
    past_due = result2['past_due'] or zero
    amount_received = t - b

Lalit Suthar

unread,
Apr 3, 2022, 2:35:39 AM4/3/22
to django...@googlegroups.com
I think this is related to your query
https://stackoverflow.com/a/28101722/8882295

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f0959467-786f-4701-9d68-abd2e54c3aaan%40googlegroups.com.

Trippy Samurai

unread,
Apr 4, 2022, 4:37:57 AM4/4/22
to Django users
Thanks for the reply Brother but it's already solved
Reply all
Reply to author
Forward
0 new messages