1👍
This is my solution
def lookups(self, request, model_admin):
ff =int(JalaliDate.today().strftime('%Y'))
print(ff)
return (
('0', 'today'),
('1', '2 days ago'),
('2', '3 days ago'),
('3', '7 days ago'),
('8', 'last month'),
('4', 'this month'),
)
def queryset(self, request, queryset):
if self.value() == '0':
return queryset.filter(start_date=date.today())
if self.value() == '1':
return queryset.filter(start_date__range=[ date.today() - timedelta(days=1),date.today() ])
if self.value() == '2':
return queryset.filter(start_date__range=[ date.today() - timedelta(days=2),date.today() ])
if self.value() == '3':
return queryset.filter(start_date__range=[ date.today() - timedelta(days=6),date.today() ])
if self.value() == '8':
return queryset.filter(start_date__range=[ date.today() - timedelta(days=int(JalaliDate.today().strftime('%d')) + 30),date.today() - timedelta(days=int(JalaliDate.today().strftime('%d')) ) ])
if self.value() == '4':
return queryset.filter(start_date__range=[ date.today() - timedelta(days=int(JalaliDate.today().strftime('%d'))),date.today() ])
Source:stackexchange.com