I have two dates:
- A query set from a database which includes a date field (1992-11-15) and date.today()
Here is my views.py
def pop(request):
start = randint(0, 2)
finish = randint(2, 5)
current_year = [date.today().year, date.today().year]
context = {
'alluserprofiles': zip(Profile.objects.all()[start:finish],
current_year),
'maleuserprofiles': zip(Profile.objects.filter(gender='male'), current_year),
'femaleuserprofiles': zip(Profile.objects.filter(gender='female'), current_year),
'start': start,
'finish': finish
}
return render(request, 'users/pop.html', context)
And here is my django template
{% for profile, year in alluserprofiles %}
<div class="container fixed-top" id="pop-up">
<div class="card text-center border-light mb-3">
<img class="card-img-top" src="{{ profile.image_prof.url }}" />
<div class="card-body">
<h5> {{ profile.user }} {{ year|sub:profile.birthday.year}}
How can I subtract them to get exact age? I am able only to manage year subtraction.
Thanks a lot