26👍
✅
Take a look at this blog post: Django: Using The Permission System
Adapted to your example:
can_fm_list = Permission.objects.get(name='can_fm_list')
newgroup.permissions.add(can_fm_list)
👤arie
8👍
For others who are looking for adding multiple permissions at once,
permissions_list = Permission.objects.all()
new_group.permissions.set(permissions_list)
- Multiple User Types For Auth in Django
- Django Rest Framework: How to enable swagger docs for function based views
- Email as username in Django
- Should I use Celery or Carrot for a Django project?
- Django ImportError: cannot import name 'ReporterProfile' from partially initialized module 'accounts.models' (most likely due to a circular import)
0👍
list of permissions add to a new group :-
group_name = request.POST.get('group_name')
permissions_list = request.POST.getlist('permission')
permissions_list_id = []
new_group = Group.objects.create(name=group_name)
for perm in permissions_list:
p = Permission.objects.get(name=perm)
permissions_list_id.append(p.id)
new_group.permissions.set(permissions_list_id)
- Django + uWSGI + Nginx + SSL – request for working configuration (emphasis on SSL)
- Django queryset filter GT, LT, GTE, LTE returns full object list
Source:stackexchange.com