5

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

Nick Dong
  • 3,638
  • 8
  • 47
  • 84

1 Answers1

6

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.

  • It works, thx. I have edited my code. but when I trying to manager `Permission` and `ContentType` at same time, I got new problem, because of onetomany relationship between them. Do you know what happened about the code? @Rickard Zachrisson – Nick Dong Jan 24 '13 at 10:03
  • What do you mean with "same time"? – Rickard Zachrisson Jan 24 '13 at 10:06
  • It means that I can see two models' data in the same web page, when I try to add or change data. Look the picture in `EDIT2`. `Job` and `Location` are two model. `Job` has a foreign key which references to `Location`. So I can select `Location` when I add jobs into `Job`. How to do that? @Rickard Zachrisson – Nick Dong Jan 24 '13 at 10:26
  • Got it. I lost a field in PermissionAdmin. thx Rickard Zachrisson. – Nick Dong Jan 24 '13 at 11:13