{% load model_tags %}

{% spaceless %}
<section class="wrapper detail_wrapper instance_detail_wrapper {{ model }}_detail_wrapper {{ model }}_{{ instance.pk }}_detail_wrapper">
  <header class="instance_header {{ model }}_header">
    <h1>{{ title|default:instance }}</h1>
  </header>

  <div class="detail instance_detail {{ model }}_detail">
    {% for name, label, value, is_list, is_link in fields %}

      {% comment %}
       #
       # This default template will render each field that belongs to the
       # instance, including the default ID primary key.  If this is not what
       # you want, it is easiest to deal with it in your style sheet.  Creating
       # a custom detail template just because you want to get rid of one field
       # seems like it has a high code to benefit ratio.  The one exception to
       # this is if your extra fields pose some sort of security vulnerability.
       # Otherwise, the set of classes on the generated elements are flexible
       # enough to handle most cases.
       #
       # If you DO want override this template for a given model (say, if you
       # want to add more interactivity, or fundamentally change the way a
       # field is rendered), you can do so with:
       #
       #  {% load model_tags %}
       #  ...
       #  {% with (appname)_(modelname)_detail_template="override_file.html" %}
       #    {% detail_block (your_instance) %}
       #  {% endwith %}
       #
       # See the example_project included with the package source for an
       # example of how this can work:
       #
       # https://github.com/mjumbewu/django-model-filters/blob/master/example_project/pepulator_factory/templates/pepulator_detail.html
       #
      {% endcomment %}

      {% if not hide_empty or value %}
        <div class="field instance_field {{ model }}_{{ name }}">
          {% if not is_list and value != None %}
            <span class="field_label instance_field_label {{ model }}_{{ name }}_label">{{ label|capfirst }}</span>
            <span class="field_value instance_field_value {{ model }}_{{ name }}_value">

              {% if value.get_absolute_url %}
                <a href="{{ value.get_absolute_url }}">{{ value }}</a>
              {% else %}
                {% if is_link %}
                  <a href="{{ value }}">{{ value }}</a>
                {% else %}
                  {{ value }}
                {% endif %}
              {% endif %}

            </span>
          {% endif %}

          {% if is_list and value.all|length %}
            {% with title=label %}
              {% list_block value.all %}
            {% endwith %}
          {% endif %}
        </div>
      {% endif %}
    {% endfor %}
  </div>
</section>
{% endspaceless %}
