def METHOD_NAME(request):
    if ("username" in request.data) and ("groups" in request.data):
        username = request.data["username"]
        groups = request.data["groups"]
        owner = get_object_or_404(Owner, user__username=username)
        for group in groups:
            try:
                accessgroup = AccessGroup.objects.get(code_name=group)
                if accessgroup in owner.accessgroup_set.all():
                    owner.accessgroup_set.remove(accessgroup)
            except ObjectDoesNotExist:
                pass
        return Response(
            OwnerWithGroupsSerializer(instance=owner, context={"request": request}).data
        )
    else:
        return HttpResponse(status=500)