将自定义按钮添加到Django应用程序的管理页面 [英] Add a custom button to a Django application's admin page

查看:141
本文介绍了将自定义按钮添加到Django应用程序的管理页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django中有一个应用程序,只有管理员可以使用这个程序。我对python / django世界很新,所以也许我的问题是微不足道的。我想要做的是在管理应用程序的这个应用程序的部分添加一个按钮来执行例程。

I have an application in Django with a routine which would be available only to the admin. I'm quite new to the python/django world, so maybe my question is trivial. What I want to do is add a button to perform the routine in this application's section of the admin app.

我很困惑,我想要做一个模板,如果是这样,如何在管理员中添加一个应用程序的html模板。或者也许有一个命令只需添加一个按钮?

I'm quite confused from there, am I suppose to make a template for it, and if it's the case, how do I add a html template for an app in the admin. Or maybe there's a command to simply add a button?

感谢您的时间

推荐答案

与管理表单交错可能很复杂,但我通常发现添加链接,按钮或额外的信息是容易和有益的。 (像一个链接到相关对象的列表,而不是编辑内联的东西,尤其是比编辑更多的东西)。

Messing with the admin forms can be complicated but i've commonly found that adding links, buttons, or extra info is easy and helpful. (Like a list of links to related objects witout making an inline, esp for things that are more viewed than edited).

Django docs


由于管理模板的模块化设计,通常是
不需要也不建议
替换整个模板。
几乎总是更好地仅覆盖

需要更改的模板部分。

Because of the modular design of the admin templates, it is usually neither necessary nor advisable to replace an entire template. It is almost always better to override only the section of the template which you need to change.

这将在表格的顶部添加一个列表。

This will add a list over the top of the form.

放在 templates / admin / [your_app] / [template_to_override]

{% extends "admin/change_form.html" %}

{% block form_top %}

{% for item in original.items %}
  {{ item }}
{% endfor %}

{% endblock %}

这篇关于将自定义按钮添加到Django应用程序的管理页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆