{% ifequal %} Confusion

22 views
Skip to first unread message

Andy Young

unread,
Nov 24, 2008, 12:52:55 AM11/24/08
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.

Malcolm Tredinnick

unread,
Nov 24, 2008, 1:00:14 AM11/24/08
to django...@googlegroups.com

Long-term bug in Django that we really will fix before 1.1 (because it's
embarrassing and makes us look kind of silly): The ifequal tag (and a
few others) don't correctly handle any kind of filtering on their
argument.

Regards,
Malcolm


Reply all
Reply to author
Forward
0 new messages