samedi 21 novembre 2015

comparing two daytimefields django template

I'm trying to use different stylesheet in django template if the time since publish is less than 15 minutes. I created the DateTimeField in my model that adds 15 minutes with time delta

blink = models.DateTimeField(default=datetime.datetime.now()+datetime.timedelta(minutes=15))

in the view.py I have defined dayandtime

dayandtime = datetime.datetime.now()

in the template I have if statement

{% if mi.blink > dayandtime %}
...
{% else %}
...

Unfortunately it goes to else even though the mi.blink is greater than dayandtime.

I tried to use answer from this question [question]: DateTime compare in django template

{% if mi.blink.date < dayandtime.date and mi.blink.time < dayandtime.time %}

but it still not working. Is it because the timedelta has been added?

Aucun commentaire:

Enregistrer un commentaire