Reputation: 1681
I need to insert the group_id
of a user(user
in auth_user
table) to auth_user_groups
table. How can we achieve this?
To insert into auth_user
table we can do
details = User(username = "somename",password = "somepassword", email = "email",
first_name = "firstname",
last_name = "lastname",
is_staff = 0,
is_active = 1,
is_superuser = 0
)
details.save()
Is there any method like
save = auth_user_groups(user_id=1,group_id = 5)
this??
Upvotes: 1
Views: 1370
Reputation: 31971
user = User.objects.get(id=1)
group = Group.objects.get(id=5)
user.groups.add(group)
Upvotes: 3