django filter older than day(s)?

前端 未结 3 778
孤独总比滥情好
孤独总比滥情好 2020-12-03 02:17

The day is the number a user will input to get the result that is older than (days from user input). For example, if user inputs 32 days, they will get the results that are

3条回答
  •  一个人的身影
    2020-12-03 03:02

    we can use Django timezone.now() with timedelta

    from datetime import timedelta
    from django.utils import timezone
    time_threshold = timezone.now() - timedelta(days=7)
    Entry.objects.filter(entered__gte=time_threshold)
    

提交回复
热议问题