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:

python manage.py shell
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

User = get_user_model()

#check to see if user exists, create it if it doesn't
User.objects.filter(username="user_name").exists() or\
    User.objects.create_user(username='user_name', 
email='[email protected]', password='blah')
 

#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? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c039cb7b-fd33-4b41-9e2a-b94e3f2d628f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to