{% load helpers %}
{% load i18n %}

<div class="card">
  <h2 class="card-header">{% trans "Related Objects" %}</h2>
  <ul class="list-group list-group-flush" role="presentation">
    {% for qs, filter_param in related_models %}
      {% with viewname=qs.model|validated_viewname:"list" %}
        {% if viewname is not None %}
        <a href="{% url viewname %}?{{ filter_param }}={{ object.pk }}" class="list-group-item list-group-item-action d-flex justify-content-between">
          {{ qs.model|meta:"verbose_name_plural"|bettertitle }}
          {% with count=qs.count %}
            {% if count %}
              <span class="badge text-bg-primary rounded-pill">{{ count }}</span>
            {% else %}
              <span class="badge text-bg-light rounded-pill">&mdash;</span>
            {% endif %}
          {% endwith %}
        </a>
        {% endif %}
      {% endwith %}
    {% empty %}
      <span class="list-group-item text-muted">{% trans "None" %}</span>
    {% endfor %}
  </ul>
</div>
