Andy Young
unread,Nov 24, 2008, 12:52:55 AM11/24/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi all,
I've attempted a shortcut in an {% ifequal %} tag and ran into some
unexpected consequences. Basically, I have two DateFields in a model
named begin_date and end_date. I am iterating through field names
({{ f }}) and their corresponding values ({{ item|getattr:f }}) to
populate a webpage. I want to catch these date-related field names to
apply different formatting using the "date" filter.
What worked:
{% ifequal f 'begin_date' %}
blah blah blah
{% else %}{% ifequal f 'end_date' %}
blah blah blah
{% endifequal %}{% endifequal %}
What didn't work:
{% ifequal f|slice:"-4:" 'date' %} blah blah blah {% endifequal
%} (matches no fields)
nor {% ifequal f|slice:"-4:" u'date' %} blah blah blah {% endifequal
%} (matches all fields)
nor {% ifequal f|slice:"-4:" date %} blah blah blah {% endifequal
%} (matches all fields)
I would imagine the "slice" filter returns a string, which is why I'm
perplexed the 'date' string didn't match. I'm probably missing some
nuance involving unicode string formatting, etc.