How can I contrast two date-time type variables in template layer?

21 views
Skip to first unread message

Dae_James

unread,
Nov 23, 2012, 1:36:27 AM11/23/12
to django...@googlegroups.com
For example, art_time is a date-time type.
As we know, {{ art_time|timesince }} return the time since art_time to now. However, I want to know how to judge whether the result is within 24 hours.
Shortly, how to know whether art_time is today or the day before today in template layer?

smcoll

unread,
Nov 23, 2012, 1:02:04 PM11/23/12
to django...@googlegroups.com
The 'timesince' filter (based on django.utils.timesince) doesn't return a datetime.timedelta object, but a formatted string.  So it would be hard to compare the resulting string with anything.  i think you're going to need to do one of the following:
  • do the comparison in your view and add the result (true/false) to the context
  • add the cutoff date to the context and compare the two datetime objects in your template
  • write/find a templatetag or filter that can do what you need

Dae James

unread,
Nov 23, 2012, 9:13:56 PM11/23/12
to django-users
Soga. Thank you very much.
 

Dae James
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/EmGMHChbbLkJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply all
Reply to author
Forward
0 new messages