Queryset of people with a birthday in the next X days

前端 未结 6 1858
春和景丽
春和景丽 2021-01-03 13:29

how do i get queryset of people with a birthday in the next X days? I saw this answer, but it does not suit me, because gets people only with current year of birth.

6条回答
  •  再見小時候
    2021-01-03 13:56

    Assuming it's datetime field do something like this (using future_date from dimosaur answer):

    Profile.objects.get(
        Q(birthday__lte=future_date),
        Q(birthday__gte=datetime.date.today())
    )
    

提交回复
热议问题