change_list html template filter block inject a css class

45 views
Skip to first unread message

Damjan Dimitrioski

unread,
Dec 18, 2014, 9:54:07 AM12/18/14
to django...@googlegroups.com
Hi,

the following block of code is an excerpt from change_list.html template:

{% block filters %}
        {% if cl.has_filters %}
          <div id="changelist-filter">
            <h2>{% trans 'Filter' %}</h2>
           


            {% for spec in cl.filter_specs %}
              {% if "somefilter" in spec|slugify %} <!-- The condition works in my project -->
                <div class="tag_type">{% admin_list_filter cl spec %}</div> <!-- This is how I add a new class, is there a simpler way to append a class attribute? -->
             
              {% else %}
                {% admin_list_filter cl spec %}
              {% endif %}

            {% endfor %}
          </div>
        {% endif %}
      {% endblock %}

What I'm looking for is to format some <li >'s based on given conditions.

Collin Anderson

unread,
Dec 19, 2014, 6:10:21 PM12/19/14
to django...@googlegroups.com
Hi,

In your custom(?) filter, you could try wrapping your text in <span class="someclass">, and then in mark_safe(), though be careful with that, security-wise.

Honestly, it might be simplest to use Javascript to apply a special class after the fact.

Collin
Reply all
Reply to author
Forward
0 new messages