What is the correct way to allow permissions?

I added a new model with one permission, and now I need to add this permission to several users on the production computer after deploying the code and running syncdb for the new application. I did not find the right way to do this. The auth docs mention User.user_permissions.add (permission), but never tell me what “permission” is or the best way to get it.

+3
source share
1 answer

Permission(which lives in django.contrib.auth.models) is the database object. You can see them all with Permission.objects.all(). They are created automatically by the post-processing signal for each model (and as indicated in the documents , you can also define your own).

To assign permissions to a user, you will first need to get the objects Permission(using Permission.objects.get(*args)), and then you can add it to the user with User.user_permissions.add(permission), as you mentioned.

, , - Django. , . , , , . , , , is_superuser True.

+4

Source: https://habr.com/ru/post/1704089/


All Articles