I'm trying to write a basic reminder app where users can enter important dates (birthdays, anniversaries, etc.) and see how much time is left until the next anniversary of that date. For example, a user can have a birthday as something like Jan 1st 1990, and I want to display for them the time until their next birthday (2 months 14 days).
I've been using the django timeuntil built in template tag, but it only works for dates in the future (it won't display anything if the date is before the current date). I'm not sure how to to go about "normalizing" the entered date to be a time in the future.
Current code:
def events(request):
relationships = Relationship.objects.filter(user=request.user)
events = Event.objects.filter(user=request.user).order_by('date')[:8]
event_date = events[0].date
if datetime.now() >= event_date:
difference = datetime.now() - event_date
event_date_new = event_date + difference
event_date = event_date_new
context = {
'relationships': relationships,
'events': events
}
return render(request, 'app/events.html', context)
Template
<td class="column-right"><h4>{{event.date|timeuntil}}</h4></td>
(It also throws an error on datetime.now() module has no attribute "now", is that an old way to find the current date?)
Thanks in advance!