def queryset(self, request, queryset):
now = timezone.now()
# When time zone support is enabled, convert "now" to the user's time
# zone so Django's definition of "Today" matches what the user expects.
if timezone.is_aware(now):
now = timezone.localtime(now)
this_year = now.replace(
month=1, day=1, hour=0, minute=0, second=0, microsecond=0
)
next_year = date(year=this_year.year + 1, month=1, day=1)
last_year = date(year=this_year.year - 1, month=1, day=1)
if self.value() == 'this':
return queryset.filter(
term_from__gte=this_year,
term_from__lt=next_year
)
elif self.value() == 'last':
return queryset.filter(
term_from__gte=last_year,
term_from__lt=this_year
)
elif self.value() == 'before':
return queryset.filter(term_from__lt=last_year)
评论列表
文章目录