Closes #5858: Implement a quick-add UI widget for related objects (#18016)

* WIP

* Misc cleanup

* Add warning re: nested quick-adds
This commit is contained in:
Jeremy Stretch
2024-11-18 14:44:57 -05:00
committed by GitHub
parent 9fe6685562
commit b4f15092db
17 changed files with 236 additions and 76 deletions

View File

@@ -0,0 +1,28 @@
{% load form_helpers %}
{% load helpers %}
{% load i18n %}
<div class="modal-header">
<h2 class="modal-title">
{% trans "Quick Add" %} {{ model|meta:"verbose_name"|bettertitle }}
</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body row">
<form
hx-post="{% url model|viewname:"add" %}?_quickadd=True&target={{ request.GET.target }}"
hx-target="#htmx-modal-content"
enctype="multipart/form-data"
>
{% csrf_token %}
{% include 'htmx/form.html' %}
<div class="text-end">
<button type="button" class="btn btn-outline-secondary btn-float" data-bs-dismiss="modal" aria-label="Cancel">
{% trans "Cancel" %}
</button>
<button type="submit" name="_quickadd" class="btn btn-primary">
{% trans "Create" %}
</button>
</div>
</form>
</div>

View File

@@ -0,0 +1,22 @@
{% load form_helpers %}
{% load helpers %}
{% load i18n %}
<div class="modal-header">
<h2 class="modal-title">
{{ object|meta:"verbose_name"|bettertitle }} {% trans "Created" %}
</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body row">
{# This content is intended to be scraped and populated in the targeted selection field. #}
<p id="quick-add-object"
data-object-repr="{{ object }}"
data-object-id="{{ object.pk }}"
data-target-id="{{ request.GET.target }}"
>
{% blocktrans with object=object|linkify object_type=object|meta:"verbose_name" %}
Created {{ object_type }} {{ object }}
{% endblocktrans %}
</p>
</div>