Django: adding multiple users to one group in admin interface

I am currently setting permissions in my project and I have assigned some permissions to one user group. Now I need to assign a large number of users to this group so that they can get group permissions.

Problem: I have to click on every user in the admin interface, add them to the group and the same for the next. It takes a lot of time. Can I select all users that should belong to a group? It will be much faster ...

If this is not possible with a standard admin interface, is there an application I can install and use to do this (eg South for database migration tasks)?

+3


source to share


1 answer


Use the django wrapper:

$ python manage.py shell
>>> from django.contrib.auth.models import User, Group
>>> the_group = Group.objects.get(name='the_name_in_admin')
>>> users = User.objects.exclude(groups__name='the_group_you_made_in_admin')
>>> for i in users:
...    i.groups.add(the_group)
...    i.save()
>>>

      



For more information on the authentication system api read the documentation

+2


source







All Articles