问题描述
如何将操作添加到第三方应用程序的管理界面?
示例:我想为模型定制一个 django.contrib.admin.Group
。
使用action表示模型的管理列表视图的批处理操作。 / p>
相关文档:
取消注册 Group
model的原始模型管理员,然后使用您自己的 ModelAdmin
注册:$ / $来自django.contrib.auth.admin导入的b
$ b
从django.contrib.auth.models导入GroupAdmin
组
class MyGroupAdmin(GroupAdmin):
actions = [...]
admin.site.unregister(Group)
admin.site.register(Group,MyGroupAdmin)
更新:如果你想从多个应用程序向 ModelAdmin
添加操作,然后您必须直接访问未记录的管理员注册表:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b / code>
How can I add actions to the admin interface of a third party app?
Example: I want to have a custom action for the model django.contrib.admin.Group
.
With "action" I mean the batch action of the admin list view of a model.
Related docs: https://docs.djangoproject.com/en/1.7/ref/contrib/admin/actions/
Unregister the original model admin for Group
model and then register it with your own ModelAdmin
:
from django.contrib.auth.admin import GroupAdmin
from django.contrib.auth.models import Group
class MyGroupAdmin(GroupAdmin):
actions = [...]
admin.site.unregister(Group)
admin.site.register(Group, MyGroupAdmin)
UPDATE: If you want to add actions to the ModelAdmin
from multiple apps then you have to directly access to the undocumented admin's registry:
def some_action(modeladmin, request, queryset):
pass
admin.site._registry[Group].actions.append(some_action)
这篇关于Django管理员对第三方模型的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!