Skip to content

Commit

Permalink
feat: add object button available in changeform
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav committed Jun 30, 2023
1 parent 3e4c5f3 commit 2a62b64
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/unfold/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
{% endif %}
{% endspaceless %}{% endblock %}

{% block nav-global-side %}
{% if has_add_permission %}
{% include "unfold/helpers/add_link.html" %}
{% endif %}
{% endblock %}

{% block content %}
<div id="content-main">
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}{% if form_url %}action="{{ form_url }}" {% endif %}method="post" id="{{ opts.model_name }}_form" novalidate>
Expand Down
2 changes: 1 addition & 1 deletion src/unfold/templates/admin/change_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

{% block nav-global-side %}
{% block object-tools %}
<ul class="object-tools ml-4">
<ul class="object-tools">
{% block object-tools-items %}
{% change_list_object_tools %}
{% endblock %}
Expand Down
12 changes: 1 addition & 11 deletions src/unfold/templates/admin/change_list_object_tools.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{% load i18n admin_urls %}

{% block object-tools-items %}
{% if has_add_permission %}
<li class="flex flex-row items-center">
{% url cl.opts|admin_urlname:"add" as add_url %}

<span class="block bg-gray-200 h-5 mx-4 w-px dark:bg-gray-700"></span>

<a href="{% add_preserved_filters add_url is_popup to_field %}" class="addlink bg-primary-600 block flex items-center h-9 justify-center -my-1 rounded-full w-9" title="{% blocktranslate with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktranslate %}">
<span class="material-symbols-outlined text-white">add</span>
</a>
</li>
{% include "unfold/helpers/add_link.html" %}
{% endif %}
{% endblock %}
19 changes: 19 additions & 0 deletions src/unfold/templates/unfold/helpers/add_link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load i18n admin_urls %}

{% if cl %}
{% url cl.opts|admin_urlname:"add" as add_url %}
{% blocktranslate with name=cl.opts.verbose_name asvar title %}Add {{ name }}{% endblocktranslate %}
{% else %}
{% url opts|admin_urlname:"add" as add_url %}
{% blocktranslate with name=opts.verbose_name asvar title %}Add {{ name }}{% endblocktranslate %}
{% endif %}

{% if add_url %}
<li class="flex flex-row items-center">
<span class="block bg-gray-200 h-5 mx-4 w-px dark:bg-gray-700"></span>

<a href="{% add_preserved_filters add_url is_popup to_field %}" class="addlink bg-primary-600 flex items-center h-9 justify-center -my-1 rounded-full w-9" title="{{ title }}">
<span class="material-symbols-outlined text-white">add</span>
</a>
</li>
{% endif %}

0 comments on commit 2a62b64

Please sign in to comment.