如何在django-admin中为复选框添加信息

huangapple go评论65阅读模式
英文:

How to add information to a checkbox in django-admin

问题

在我的Django管理界面(change_form)中,我有几个复选框(不仅仅是删除),其中一些位于TabularInline中。我想让用户知道当他们选择一个复选框时会发生什么。请参见下面的图片。

我已经搜索了很多,但找不到任何信息?我不知道该在哪里搜索!!表单!

如何在django-admin中为复选框添加信息

英文:

In my Django admin (change_form) I have several checkboxes.(not only delete) some of them in TabularInline.
I want to let the users know what is going to be happened when they select a checkbox. See picture below.
I have searched alot but couldn’t find anything? I don't know where to search!! Form!

如何在django-admin中为复选框添加信息

答案1

得分: 0

需要覆盖tabular.html模板

这部分负责复选框的显示

原始内容

{% if inline_admin_formset.formset.can_delete %}
  <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
{% endif %}

修改后

{% if inline_admin_formset.formset.can_delete %}
  <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}test{% endif %}</td>
{% endif %}

结果

如何在django-admin中为复选框添加信息

在创建修改后的tabular.html版本之后,将其设置为要更改的Inline类的模板。

class YourInline(admin.TabularInline):
    template = 'your_path_to_modified_tabular_html/tabular.html'
英文:

You need to override tabular.html template

this part respond for chek box display

Original

{% if inline_admin_formset.formset.can_delete %}
  <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
{% endif %}

Modified

{% if inline_admin_formset.formset.can_delete %}
  <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}test{% endif %}</td>
{% endif %}

Result

如何在django-admin中为复选框添加信息

After you create modified version of tabular.html set it as template in Inline class you want to change.

class YourInline(admin.TabularInline):
    template = 'your_path_to_modified_tabular_html/tabular.html'

huangapple
  • 本文由 发表于 2020年1月6日 21:12:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定