def follow(request): ''' A view to follow other users ''' output = {} if request.method == "POST": data = request.POST.copy() data['user'] = request.user.id form = forms.FollowForm(data=data) if form.is_valid(): follow = form.save() if follow: output['follow'] = dict(id=follow.id) else: output['errors'] = dict(form.errors.items()) else: form = forms.FollowForm() return HttpResponse(json.dumps(output), content_type='application/json')
def follow(request): ''' A view to follow other users ''' output = {} if request.method == "POST": form = forms.FollowForm(user=request.user, data=request.POST) if form.is_valid(): follow = form.save() if follow: output['follow'] = dict(id=follow.id) if not request.is_ajax(): return redirect_to_next(request) else: output['errors'] = dict(form.errors.items()) return HttpResponse(json.dumps(output), content_type='application/json')