1👍
✅
This, to begin with, will help you understand the error you’re getting
group_id = Group.objects.get(id=1)
Here, group_id
becomes an instance of the model Group
.
Group
and its instances have attributes name
, and permissions
.
group_id.groups.add(new_user)
Is nonsense. groups
is an attribute of User
and not Group
.
Replace group_id with new_user :
new_user.groups.add(group_id)
This will add group_id (which should be named group instead) to the list of groups new_user is member of.
Source:stackexchange.com