def toggleFollow(request): current_user = InstaUser.objects.get(pk=request.user.pk) follow_user_pk = request.POST.get('follow_user_pk') follow_user = InstaUser.objects.get(pk=follow_user_pk) try: if current_user != follow_user: if request.POST.get('type') == 'follow': connection = UserConnection(creator=current_user, following=follow_user) connection.save() elif request.POST.get('type') == 'unfollow': UserConnection.objects.filter(creator=current_user, following=follow_user).delete() result = 1 else: if request.POST.get('type') == 'follow': connection = UserConnection(creator=current_user, following=follow_user) connection.save() elif request.POST.get('type') == 'unfollow': UserConnection.objects.filter(creator=current_user, following=follow_user).delete() result = 2 except Exception as e: print(e) result = 0 return { 'result': result, 'type': request.POST.get('type'), 'follow_user_pk': follow_user_pk }
def toggleFollow(request): #拿到follow_user_id,follow_user_pk是从index.js中传过来的key follow_user_pk = request.POST.get('follow_user_pk') #根据follow_user_id拿到follow_user follow_user = InstaUser.objects.get(pk=follow_user_pk) current_user = InstaUser.objects.get(pk=request.user.pk) try: if current_user != follow_user: if request.POST.get('type') == 'follow': connection = UserConnection(creator=current_user, following=follow_user) connection.save() elif request.POST.get('type') == 'unfollow': connection = UserConnection.objects.filter( creator=current_user, following=follow_user) connection.delete() result = 1 else: result = 0 except Exception as e: print(e) result = 0 return { 'result': result, 'follow_user_pk': follow_user_pk, 'type': request.POST.get('type') }
def followUnfollow(request): follow_pk = request.POST.get('follow_user_pk') follow = InstaUser.objects.get(id=follow_pk) user_pk = request.POST.get('user_pk') curr_user = InstaUser.objects.get(id=user_pk) try: conn = UserConnection(creator=curr_user, following=follow) conn.save() result = 1 except Exception as e: conn = UserConnection.objects.get(creator=curr_user, following=follow) conn.delete() result = 0 return { 'result': result, }
def toggleFollow(request): follow_user_pk = request.POST.get('follow_user_pk') to_user = CustomUser.objects.get(pk=follow_user_pk) from_user = CustomUser.objects.get(pk=request.user.id) try: if from_user != to_user: if request.POST.get('type') == 'follow': connection = UserConnection(from_user=from_user, to_user=to_user) connection.save() elif request.POST.get('type') == 'unfollow': UserConnection.objects.filter(from_user=from_user, to_user=to_user).delete() result = 1 else: result = 0 except Exception as e: print(e) result = 0 return { 'result': result, 'type': request.POST.get('type'), 'follow_user_pk': follow_user_pk }