{% extends "sacrud/types/SacrudBase.jinja2" %}

{% block sacrud_column %}
  {% for fk_col in col.foreign_keys %}
      {% set fk_table=fk_col.column.table %}
      {% for rel in  relationships %}
        {% if rel['cls'].__tablename__==fk_table.name %}
          <select class="sacrud_fk {{ css_styles }}"
                  id="sacrud_fk_{{ col.name }}" name="{{ col.name }}">
            {% for x in session.query(rel['cls']).all() %}
              {% set pk=x.__mapper__.primary_key[0].name %}
              <option value='{{ getattr(x, pk) }}'
                {% if obj %}
                  {% if value==getattr(x, pk) %}
                    selected
                  {% endif %}
                {% endif %}>
                {{ x.__repr__() }}
              </option>
            {% endfor %}
          </select>
        {% endif %}
      {% endfor %}
  {% endfor %}
{% endblock %}
