Hi,
I'm trying to set a permission for a user that I'm creating with a python script. I've tested and found that the codename for the permission is "display_data.settings" using the following:
from django.contrib.auth.models import User
user_name = User.objects.get(username="user_name")
user_name.get_all_permissions()
set([u'display_data.settings'])
I'm trying to set this permission for the user with the following:
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User, Permission
#check to see if user exists, create it if it doesn't
User.objects.filter(username="user_name").exists() or\
#add permissions to user
u = User.objects.get(username="user_name")
permission = Permission.objects.get(name='display_data.settings')
u.user_permissions.add(permission)
When I run this, I get the following error:
django.contrib.auth.models.DoesNotExist: Permission matching query does not exist.
Can anybody tell me what I'm missing?