How to manage permission table in django admin

enter image description here

When I use django admin

, can I get a control input Groups

, Users

the control panel? How can I get the table control input Permission

as shown above? I am using django 1.4. thanks for ur time.

Editorial staff:

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 editing, I got.

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

      

ContentType can onetomany

resolve. How to deal with these two models in the admin? It works great before adding:

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

      

EDIT2: enter image description here

+3


source to share


1 answer


I'm not sure how you imagined the ui is behaving or looking, 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)

      



You might be able to pick it up from there and customize it however you want.

+5


source







All Articles