-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
How to restrict access to parts of Django admin? | ||
================================================= | ||
|
||
You can enable and restrict access to specific parts of Django admin using the permission system. | ||
When a model is added, by default, Django creates three permissions. :code:`add, change and delete` | ||
|
||
|
||
Admin uses these permissions to decide access for users. For a user with :code:`is_superuser=False`, and no permissions, the admin looks like this | ||
|
||
.. image:: access_no_perms.png | ||
|
||
If you add a permission :code:`user.user_permissions.add(Permission.objects.get(codename="add_hero"))`, the admin starts looking like this | ||
|
||
.. image:: access_one_perm.png | ||
|
||
You can add more complex logic to restrict access by changing these methods:: | ||
|
||
def has_add_permission(self, request): | ||
... | ||
|
||
def has_change_permission(self, request, obj=None): | ||
... | ||
|
||
def has_delete_permission(self, request, obj=None): | ||
... | ||
|
||
def has_module_permission(self, request): | ||
... |
This file contains 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
This file contains 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