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:
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.
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With