Django Admin Cookbook: How to do things with Django Admin by Shabda Raaj

Django Admin Cookbook: How to do things with Django Admin by Shabda Raaj

Author:Shabda Raaj [Raaj, Shabda]
Language: eng
Format: epub
Publisher: Agiliq Info Solutions India Pvt Ltd
Published: 2018-07-29T23:00:00+00:00


1. How to restrict Django admin to specific users?

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. If a non-staff tries to access the admin, they see a message like this.

2. 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. add, change and delete

Admin uses these permissions to decide access for users. For a user with is_superuser=False, and no permissions, the admin looks like this

If you add a permission user.user_permissions.add(Permission.objects.get(codename="add_hero")), the admin starts looking like this

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): ...



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.