V
V
Vitaly2016-08-18 18:09:20
Django
Vitaly, 2016-08-18 18:09:20

How to log out a user log out of a Django group?

I'm making groups on the site, and I need to implement an exit when a button is clicked.
There is a f-ya that takes id, you need to check if the user is in a group, and remove this group from his list of groups. There is an assumption of a possible implementation, but I don’t know what to do next

def leave_group(request, g_id):
    g = get_object_or_404(request.user.groups, id=g_id)
    # если исключение не выкинуло, значит юзер в группе...
    u = request.user
    u.groups.delete...
    return HttpResponse('ok')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2016-08-18
@MrCute

@login_required
def leave_group(request, g_id):
    request.user.groups.remove(g_id)
    return HttpResponse('ok')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question