Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Add multiple user to one group in admin interface

At the moment i'm settting up the permissions in my project and i assigned some permissions to one user group. Now i have to assign a large number of users to this group, so that they can us the permissions of the group.

Problem: I have to click on every user in the admin interface, add them to the group and the same for the next ones. This takes a large amount of time. Is it possible to select anywhere all users that should belong to a group? That would be much faster...

If it's not possible with the standard admin interface, is there an app I can install and use for this (like "South" for database migration tasks)?

like image 826
flammi88 Avatar asked Jan 22 '13 12:01

flammi88


People also ask

Can I have two user models in Django?

You can have in your models two user classes that extend from the USER model.


1 Answers

Use the django shell:

$ 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 api of the authentication system, have a read through the documentation

like image 68
Burhan Khalid Avatar answered Sep 22 '22 14:09

Burhan Khalid