{% extends 'base.html' %}
{% load form_helpers %}

{% block content %}
    <h1>{% block title %}Add {{ model_name|title }}{% endblock %}</h1>
    <p>{{ table.rows|length }} {{ parent_model_name }} selected</p>
    <form action="." method="post" class="form form-horizontal">
        {% csrf_token %}
        {% if request.POST.return_url %}
            <input type="hidden" name="return_url" value="{{ request.POST.return_url }}" />
        {% endif %}
        {% for field in form.hidden_fields %}
            {{ field }}
        {% endfor %}
        <div class="row">
            <div class="col-md-7">
                <div class="panel panel-default">
                    {% include 'inc/table.html' %}
                </div>
            </div>
            <div class="col-md-5">
                {% if form.non_field_errors %}
                    <div class="panel panel-danger">
                        <div class="panel-heading"><strong>Errors</strong></div>
                        <div class="panel-body">
                            {{ form.non_field_errors }}
                        </div>
                    </div>
                {% endif %}
                <div class="panel panel-default">
                    <div class="panel-heading"><strong>{{ model_name|title }} to Add</strong></div>
                    <div class="panel-body">
                        {% for field in form.visible_fields %}
                            {% if not form.custom_fields or field.name not in form.custom_fields %}
                                {% render_field field %}
                            {% endif %}
                        {% endfor %}
                        {% if form.custom_fields %}
                            {% render_custom_fields form %}
                        {% endif %}
                    </div>
                </div>
                <div class="form-group text-right">
                    <div class="col-md-12">
                        <button type="submit" name="_create" class="btn btn-primary">Create</button>
                        <a href="{{ return_url }}" class="btn btn-default">Cancel</a>
                    </div>
                </div>
            </div>
        </div>
    </form>
{% endblock %}
