Nick Dong
Nick Dong

Reputation: 3736

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

Upvotes: 5

Views: 6952

Answers (1)

Rickard Zachrisson
Rickard Zachrisson

Reputation: 985

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.

Upvotes: 6

Related Questions