On 3/14/07, bgcooper <[EMAIL PROTECTED]> wrote:
>
> Our app uses a number of state integers mapped to names inside a
> dictionary. The state stored in the model is an integer and we use the
> dictionary to pull out the names whenever we want to.
>
> We have a custom template filter to get the names from the template
> context. e.g.
>
> {{ message.state|stateName }}

First, you could see 'choices' parameter in CharField or IntegerField,
and django has a handly function get_FOO_display() to get the
corresponding string value of a special key, just like what you want.
In db_api document, searcin get_FOO_display you'll get the answer.

>
> We cannot, however, seem to get this working inside condition
> statements in a template e.g.
>
> {% ifequal message.state|stateName "Sent" %}
>
> Is this a known limitation? I'd rather use this in my templates than
> some magic number associated with the state.
>
>
Second, yeah there is limit for ifequal, you can not using filter to
template var. There is not a good sulotion I think, except you can use
CatchTag written by me. http://www.djangosnippets.org/snippets/10/

For example:

{% catch as state %}{{ message.state|stateName }}{% endcatch %}
{% ifequal state "Sent" %}


-- 
I like python!
UliPad <<The Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to