1👍
✅
Only superuser has all permissions. Permissions should be added to non-superusers.
from django.contrib.auth.models import Permission
...
b.user_permissions.add(Permission.objects.get(content_type__app_label='student',
codename='add_user'))
b.user_permissions.add(Permission.objects.get(content_type__app_label='student',
codename='change_user'))
b.user_permissions.add(Permission.objects.get(content_type__app_label='student',
codename='delete_user'))
0👍
try this:
from django.contrib.auth.models import User, Group, Permission
b = User.objects.create_user('mina','mina@dd.dd','123456')
permission = Permission.objects.get(name='Can add user') # get permission by name
b.user_permissions.add(permission) #add permission to user
b.save()
Or you can create a group
with all permissons that you want, and add user to this group like this:
group = Group.objects.get(name='wizard')
user.groups.add(group)
And take a look at this.
- [Answer]-Django at extra_context 'unicode' object does not support item assignment
- [Answer]-How can I get fixed output from my django database
- [Answer]-Django-cms: ImportError: No module named cms
- [Answer]-Override ForeignKey relationship in child model?
0👍
Looks like you are using a custom user model. Your user model needs to inherit the PermissionsMixin
from django.contrib.auth.models import PermissionsMixin
Also it’s recommended that your model inherits from AbstractBaseUser
See https://docs.djangoproject.com/en/dev/topics/auth/customizing/#specifying-a-custom-user-model
class User(AbstractBaseUser, PermissionsMixin):
...
- [Answer]-How can i mention current date in django rest framework filter field
- [Answer]-Django : Error: No module named apps – Django version 1.4.5
Source:stackexchange.com