remove user from a specific group in django

395 views
Skip to first unread message

José Ángel Encinas

unread,
Aug 16, 2022, 5:15:50 PM8/16/22
to Django users
hi guys, im trying to remove user from a specific group using a function in django but can to do it, can help me someone?

this is the function
def accesstosystem(request):
    usuario = User.objects.filter(groups__name='revisión')
    user = User.objects.get(username=usuario)
    group = Group.objects.get(name='revisión')
    user.groups.remove(group)

kind regards 

Ryan Nowakowski

unread,
Aug 17, 2022, 12:11:46 PM8/17/22
to django...@googlegroups.com
usuario isn't a username, it's a QuerySet so I don't think:

User.objects.get(username=usuario)

... will work.

Please post the specific error you're getting including any traceback.

subin

unread,
Aug 18, 2022, 8:28:53 PM8/18/22
to django...@googlegroups.com
Please let me know if that sounds okay.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/482D57FC-EA71-4681-B824-92517C65770A%40fattuba.com.
Reply all
Reply to author
Forward
0 new messages