I\'m trying to get the birthdays in the upcoming 20 days, given the below Person
model:
class Person(models.Model):
dob = models.DateField() #
Caveat: I believe calendars and time is hard. As a result, I feel obligated to warn you that I haven't rigorously tested my proposal. But of course, I think it should work. :)
Unfortunately, I think you should abandon date objects as the additional complication of year data precludes easy selects. Rather, I propose storing the birthday as a MMDD
string (comparison of strings works, as long as you format them consistently). You can then compute your next_20_days
and convert that to a similar MMDD
string, as well as today, then use them as values to compare against.
I have three edge cases you should definitely make sure work:
OR
query using Q
objects.Edit: See also:
and so on. I just did a Google search for "stack overflow birthday select".