Queryset of people with a birthday in the next X days

前端 未结 6 2144
天命终不由人
天命终不由人 2021-01-03 13:45

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:57

    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())
    )
    

提交回复
热议问题