Created
November 2, 2013 03:33
-
-
Save siteshen/7275208 to your computer and use it in GitHub Desktop.
Django admin with read-only permission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib import admin | |
| class ReadOnlyAdmin(admin.ModelAdmin): | |
| """A ModelAdmin with read only permission.""" | |
| def get_list_display(self, request): | |
| return self.get_readonly_fields(request) | |
| def get_readonly_fields(self, request, obj=None): | |
| readonly_fields = [] | |
| for field in self.model._meta.fields: | |
| readonly_fields.append(field.name) | |
| return readonly_fields | |
| def has_add_permission(self, request): | |
| return False | |
| def has_delete_permission(self, request, obj=None): | |
| return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment