{% load relations %}
{% load django_tables2 %}
<div id="rel_{{ object.id }}_{{ target.name }}" hx-swap-oob="true">

  {% block relations_list %}
    {% relations_list_table relations target as table %}
    {% if table.data %}
      {% render_table table %}
    {% endif %}
  {% endblock relations_list %}

  {% block relations_create %}
    {% if edit %}
      {% for relation in possible_relations %}
        {% if relation.model_class.get_add_permission in perms %}
          {% url "apis_core:relations:create_relation" relation as baseurl %}
          {% url "apis_core:relations:create_relation_form" relation as baseurlform %}
          {% if target.model_class in relation.model_class.subj_list and object.self_contenttype.model_class in relation.model_class.obj_list %}
            <a href="{{ baseurl }}?obj_content_type={{ object.self_contenttype.id }}&obj_object_id={{ object.id }}&subj_content_type={{ target.id }}"
               class="btn btn-sm btn-outline-secondary"
               hx-get="{{ baseurlform }}?obj_content_type={{ object.self_contenttype.id }}&obj_object_id={{ object.id }}&subj_content_type={{ target.id }}&hx=true&reverse=true"
               hx-target="#relation-dialog-content"
               onclick="relationdialog.showModal();">{{ relation.model_class.reverse_name }}</a>
          {% endif %}
          {% if target.model_class in relation.model_class.obj_list and object.self_contenttype.model_class in relation.model_class.subj_list %}
            <a href="{{ baseurl }}?subj_content_type={{ object.self_contenttype.id }}&subj_object_id={{ object.id }}&obj_content_type={{ target.id }}"
               class="btn btn-sm btn-outline-secondary"
               hx-get="{{ baseurlform }}?subj_content_type={{ object.self_contenttype.id }}&subj_object_id={{ object.id }}&obj_content_type={{ target.id }}&hx=true"
               hx-target="#relation-dialog-content"
               onclick="relationdialog.showModal();">{{ relation.model_class.name }}</a>
          {% endif %}
        {% endif %}
      {% endfor %}
    {% endif %}
  {% endblock relations_create %}

</div>
