django mixin可以轻松地向任何modeladmin添加url
admin-extra-urls的Python项目详细描述
可插入的Django应用程序,它提供一个单一的混合类^ {TT1}$ 轻松地向任何modeladmin添加新的url(以及屏幕上的相关按钮)。
它提供了两个装饰符link()和action()。
- link()用于多个记录。它将在“更改列表”视图中生成一个按钮。
- action()只对一条记录起作用。它将在“更改窗体”视图中生成一个按钮。
安装
pipinstalladmin-extra-urls
安装后将其添加到INSTALLED_APPS
INSTALLED_APPS=(...'admin_extra_urls',)
如何使用
fromadmin_extra_urls.extrasimportExtraUrlMixin,link,actionclassMyModelModelAdmin(ExtraUrlMixin,admin.ModelAdmin):@link()# /admin/myapp/mymodel/update_all/defupdate_all(self,request):......@action()# /admin/myapp/mymodel/update/10/defupdate(self,request,pk):obj=self.get_object(pk=pk)...
您不需要返回httpresponse。默认行为是:
- with link() button is displayed in the ‘list’ view and the browser will be redirected to ^{tt7}$
- with action() button is displayed in the ‘update’ view and the browser will be redirected to ^{tt8}$
link()/action()选项
path | None | path url path for the action. will be the url where the button will point to. |
label | None | label for the button. by default the “labelized” function name |
icon | ‘’ | icon for the button |
permission | None | permission required to use the button. Can be a callable (current object as argument). |
css_class | “btn btn-success” | extra css classes to use for the button |
order | 999 | in case of multiple button the order to use |
visible | lambda o: o and o.pk | callable or bool. By default do not display “action” button if in add mode |
与其他库集成
Django进出口
@admin.register(Rule)classRuleAdmin(ExtraUrlMixin,ImportExportMixin,BaseModelAdmin):@link(label='Export')def_export(self,request):returnself.export_action(request)@link(label='Import')def_import(self,request):returnself.import_action(request)
链接
Stable | |||
Development | |||
Project home page: | https://github.com/saxix/django-admin-extra-urls | ||
Issue tracker: | https://github.com/saxix/django-admin-extra-urls/issues?sort | ||
Download: | http://pypi.python.org/pypi/admin-extra-urls/ |