django,如何删除权限表单

时间:2018-12-11 15:13:30

标签: django forms permissions

DJANGO 1.8

我将从

删除完整的表格“ permissions”

.. auth / group / add

.. auth / group / change

因为我使用了第二个自定义管理界面。

我仅创建了以下代码,但仅修改了权限列表:

from django.contrib.auth.admin import GroupAdmin   
 class MyGroupAdmin(GroupAdmin):
    def get_form(self, request, obj=None, **kwargs):
        # Get form from original GroupAdmin.
        form = super(MyGroupAdmin, self).get_form(request, obj, **kwargs)
        if 'permissions' in form.base_fields:
            permissions = form.base_fields['permissions']
            permissions.queryset = permissions.queryset.exclude(content_type__app_label__in=['admin', 'auth'])
        return form

有可能吗? 谢谢

0 个答案:

没有答案