Django-admin具有可调用功能 [英] Django-admin with callable functions

查看:103
本文介绍了Django-admin具有可调用功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django-admin视图仅允许更改模型对象的值。但是,是否可以以简单的方式配置或更改管理员视图,以便开始在对象上显示功能?我不是在可以在对象列表顶部的下拉菜单中引入的功能。我的意思是直接访问模型对象上的函数?

Django-admin view allows only for changing the values of model objects. Is it, however, possible to configure or change in an easy way the admin view so that it starts exposing functions on objects? I'm not talking about the functions that can be introduced in the drop-down menu on top of the object list. What I mean is a direct access to functions on model objects?

推荐答案

您可以通过在您的网址中添加^ admin / ...url将您自己的视图添加到管理员网站CONF。您可以使用它来扩展管理站点相对容易,并通过您自己的视图公开模型方法。请参阅创建自定义管理视图此处: http: //www.djangobook.com/en/1.0/chapter17/ (另一种方法和注意事项: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-views-to-admin-sites )。

You can add your own view to the admin site by adding an "^admin/..." url in your url conf. You can use this to extend the admin site relatively easy and expose model methods through your own view. See Creating Custom Admin Views here: http://www.djangobook.com/en/1.0/chapter17/ (and another approach and notes here: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-views-to-admin-sites ).

要在管理员网站的模型更改表单中添加一个按钮,请覆盖 change_form.html 所需型号的模板(请参阅 https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates )。

To add this as a button in the model's "change form" in the admin site, override the change_form.html template for the required models (see https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates ).

你可能会要覆盖对象工具块,该块保存页面右上角的按钮。 (在Django 1.3中,您可以扩展对象工具项目块,请参阅: https://code.djangoproject .com / ticket / 12694

You will probably want to override the object-tools block, which holds the buttons in the top right side of the page. (In Django 1.3 you can extend the object-tools-items block instead, see: https://code.djangoproject.com/ticket/12694 )

(我确定可以建立一个漂亮的插件/应用程序,自动将对象工具添加到模型中在ModelAdmin中定制object_tools属性,其中包含模型方法列表。让我知道id,您会发现这样的事情。)

(I am quite sure one can build a nice plugin/app that automatically adds object-tools to a model from a custom "object_tools" property in the ModelAdmin with a list of model methods. Let me know id you find something like this.)

这篇关于Django-admin具有可调用功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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