Hello,

I am trying to render a model field in a django template, and, based on the 
value of the field, I want to specify a different CSS class.  Right now, my 
solution is this:

<span class="label {% if myobject.state == 'Scheduled' %}label-default
                   {% elif myobject.state == 'Provisioning' %}label-primary
                   {% elif myobject.state == 'Active' %}label-success
                   {% elif myobject.state == 'Deleting' %}label-primary
                   {% elif myobject.state == 'Ended' %}label-info
                   {% endif %}">{{ myobject.state }}</span>

This works, but seems like a really ugly solution and a bunch of logic in 
the template.  Is there a better way of doing this?  My thought was to put 
the class names as another field in the model, but that seems like it would 
violate the MVC (or MVT) separation. Any ideas?

Thanks in advance,
treyd

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a3adb62-f3d7-4cc2-8c97-add34cf757ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to