django add user to group

Solutions on MaxInterview for django add user to group by the best coders in the world

showing results for - "django add user to group"
Serena
11 Nov 2018
1from django.contrib.auth.models import Group, User
2 
3g = Group.objects.get(name='My Group Name')
4users = User.objects.all()
5for u in users:
6    g.user_set.add(u)
Serena
24 Aug 2018
1from django.contrib.auth.models import Group, User
2tonystark=User.objects.get(id=pk)
3hulk=Group.objects.get(name='groupname')
4hulk.user_set.add(tonystark)
Nicole
30 Jul 2016
1from django.contrib.auth.models import Group
2my_group = Group.objects.get(name='my_group_name') 
3my_group.user_set.add(your_user)