Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to manage permission table in django admin

enter image description here

When I use django admin, I can get Groups, Users management entrance on the dashboard? How can I get Permission table management entrance as pictures shows above? I am using django 1.4 . thx for ur time.

EDITED:

from django.contrib import admin
from django.contrib.auth.models import Permission, ContentType

class PermissionAdmin(admin.ModelAdmin):

    fieldsets = [  
        (None,          {'fields': ['name','codename']}),  

    ]  
    list_display = ('name', 'codename')      

class ContentTypeAdmin(admin.ModelAdmin):

    fieldsets = [  
        (None,          {'fields': ['app_label','model']}),  
        ('More info',   {'fields': ['name','codename'], 'classes': ['collapse']}),  

    ]  
    list_display = ('app_label', 'model')         

admin.site.register(Permission, PermissionAdmin)
admin.site.register(ContentType, ContentTypeAdmin)

After edited, I got.

django.core.exceptions.ImproperlyConfigured: 'ContentTypeAdmin.fieldsets[1][2]['fields']' refers to field 'codename' that is missing from the form.

ContentType could onetomany to Permission. How to deal with to these two model in admin? It works fine before I add:

('More info',   {'fields': ['name','codename'], 'classes': ['collapse']}),  

EDIT2: enter image description here

like image 846
Nick Dong Avatar asked Jan 24 '13 08:01

Nick Dong


People also ask

How do I give permission to admin in Django?

The Django admin site uses permissions as follows: Access to view objects is limited to users with the “view” or “change” permission for that type of object. Access to view the “add” form and add an object is limited to users with the “add” permission for that type of object.

How do I set permissions in Django?

With Django, you can create groups to class users and assign permissions to each group so when creating users, you can just assign the user to a group and, in turn, the user has all the permissions from that group. To create a group, you need the Group model from django. contrib. auth.

How do I restrict access to parts of Django admin?

Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .


1 Answers

I'm not sure how you imagined the ui to behave or look but you can do this:

from django.contrib.auth.models import Permission

class PermissionAdmin(admin.ModelAdmin):
    model = Permission
    fields = ['name']

admin.site.register(Permission, PermissionAdmin)

Perhaps you can pick it up from there and tweak it as you wish.

like image 177
Rickard Zachrisson Avatar answered Sep 19 '22 18:09

Rickard Zachrisson