python – Bootstrap Django: Only show Active field in tabs-ThrowExceptions

Exception or error:

I`ve got two tabs:

<ul class="nav nav-tabs" id="myTab" role="tablist">
          <li class="nav-item">
            <a class="nav-link active" id="open-tab" data-toggle="tab" href="#open" role="tab" aria-controls="open" aria-selected="true">Active Projects</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" id="close-tab" data-toggle="tab" href="#close" role="tab" aria-controls="close" aria-selected="false">Inactive Projects</a>
          </li>
        </ul>

The Model of the Application got a field {{app.is_active}}.

Is Filtering the tab with a script is the best option to only show “Active projects” in the active tab and “Inactive projects” in the inactive tab?

Many Thanks,

How to solve:

if you’re not using django rest frame work.
it has a simple solution:

<ul class="nav nav-tabs" id="myTab" role="tablist">
    {% for item in app_list %}
        {% if item.is_active %}
              <li class="nav-item active">
                   <a class="nav-link active" id="open-tab" data-toggle="tab" href="#open" role="tab" aria-controls="open" aria-selected="true">{{ item }}</a>
             </li>
      {% else %}
             <li class="nav-item">
                   <a class="nav-link" id="close-tab" data-toggle="tab" href="#close" role="tab" aria-controls="close" aria-selected="false">{{ item }}</a>
            </li>
        {% endif %}
   {% endfor %}
</ul>

Leave a Reply

Your email address will not be published. Required fields are marked *