python - How to compare dates in Django -
i compare date current date in django, preferably in template, possible before rendering template. if date has passed, want "in past" while if in future, want give date.
i hoping 1 this:
{% if listing.date <= %} in past {% else %} {{ listing.date|date:"d m y" }} {% endif %}
with being today's date, not work. couldn't find in django docs. can give advice?
compare date in view, , pass in_the_past
(boolean) extra_context.
or better add model property.
from datetime import date @property def is_past_due(self): return date.today() > self.date
then in view:
{% if listing.is_past_due %} in past {% else %} {{ listing.date|date:"d m y" }} {% endif %}
basically template not place date comparison imo.
Comments
Post a Comment