4👍
✅
The author confirmed that this is the correct way to do this https://github.com/etianen/django-python3-ldap/issues/74#issuecomment-304396431
def sync_all_user_group_relations(user, data):
ldap_groups = list(data.get('memberOf', ()))
for group in ldap_groups:
if group == 'CN=InternalBilling-Users,OU=ABC-Users,OU=Groups,DC=abc,DC=abc,DC=com':
g = Group.objects.get(name='Billing clerks')
user.is_staff=True
user.save()
g.user_set.add(user)
elif group == 'CN=InternalBilling-Admin,OU=ABC-Users,OU=Groups,DC=abc,DC=abc,DC=com':
g = Group.objects.get(name='Billing admins')
user.is_staff=True
user.save()
g.user_set.add(user)
Source:stackexchange.com