title: Can't Add/Accept and Decline/Cancel Friend requests on Django
body: <p>Able to Send Friend requests successfully but responding to the requests are an issue. When you press Accept to Add, the button is removed but the Friend isn't added or when you press Cancel to Decline, nothing happens. </p>
  
  <p>Tried adding a forms</p>
  
  <pre><code>class Add_Friend(forms.ModelForm):
      model = UserProfile
  
      def add_friend(request, user_profile):
          request.notification_set.get(type=Notification.FRIEND_REQUEST, sender=user_profile.user.username).delete()
          request.friends.add(user_profile)
          user_profile.friends.add(self)
          request.friend_requests.remove(user_profile)
          noti = Notification.objects.create(owner=user_profile, type=Notification.ACCEPTED_FRIEND_REQUEST, sender=self.user.username)
          user_profile.notification_set.add(noti)
          return self.friends.count()
  </code></pre>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      first_name = models.CharField(blank=True, max_length=128)
  
      friends = models.ManyToManyField('self', blank=True, related_name='friends')
      friend_requests = models.ManyToManyField('self', blank=True, related_name='friend_requests')
  
      def send_friend_request(self, user_profile):
          self.friend_requests.add(user_profile)
          noti = Notification.objects.create(owner=self, type=Notification.FRIEND_REQUEST, sender=user_profile.user.username)
          self.notification_set.add(noti)
          return self.friend_requests.count()
  
      def add_friend(self, user_profile):
          self.friend_requests.remove(user_profile)
          self.notification_set.get(type=Notification.FRIEND_REQUEST, sender=user_profile.user.username).delete()
          self.friends.add(user_profile)
          user_profile.friends.add(self)
          noti = Notification.objects.create(owner=user_profile, type=Notification.ACCEPTED_FRIEND_REQUEST, sender=self.user.username)
          user_profile.notification_set.add(noti)
          return self.friends.count()
  
      def cancel_friend_request(self, user_profile):
          self.friend_requests.remove(user_profile)
          self.notification_set.get(type=Notification.FRIEND_REQUEST, sender=user_profile.user.username).delete()
          noti = Notification.objects.create(owner=user_profile, type=Notification.DECLINED_FRIEND_REQUEST, sender=self.user.username)
          user_profile.notification_set.add(noti)
          return self.friend_requests.count()
  
      def __str__(self):
          return self.get_first_name()
  
      #Takes you to the userprofile page
      def get_absolute_url(self):
          return "/users/{}".format(self.id)
  </code></pre>
  
  <pre><code>@method_decorator(login_required, name='dispatch')
  class SendFriendRequestView(View):
  
      def get(self, request, *args, **kwargs):
          profile_id = request.GET.get('profile_id')
          requester_id = request.GET.get('requester_id')
          target = UserProfile.objects.get(id=profile_id)
          requester = UserProfile.objects.get(id=requester_id)
          target.send_friend_request(requester)
          message = 'Friend request to {} sent!'.format(target.visible_name)
          messages.info(request, message)
          return redirect('profile', username=target.user.username)
  
  
  @method_decorator(login_required, name='dispatch')
  class CancelFriendRequestView(View):
  
      def cancel_friend_request(request, id):
      if request.user.is_authenticated():
          user = get_object_or_404(User, id=id)
          frequest, created = FriendRequest.objects.filter(
              from_user=request.user,
              to_user=user).first()
          frequest.delete()
          return HttpResponseRedirect('/users')
  
  
  @method_decorator(login_required, name='dispatch')
  class AddFriendView(View):
  
      def get(self, request, *args, **kwargs):
          try:
              profile_id = request.GET.get('profile_id')
              requester_id = request.GET.get('requester_id')
              target = UserProfile.objects.get(id=profile_id)
              requester = UserProfile.objects.get(id=requester_id)
              target.add_friend(requester)
              message = 'Added friend {}!'.format(target.visible_name)
              messages.info(request, message)
              return redirect('friends', username=target.user.username)
          except Exception as e:
              print('Error: {}'.format(e))
  </code></pre>
  
  <pre><code>url(r'^friend-request/send/(?P&lt;id&gt;[\w\-]+)/$', send_friend_request),
  url(r'^friend-request/cancel/(?P&lt;id&gt;[\w\-]+)/$', cancel_friend_request),
  url(r'^friend-request/accept/(?P&lt;id&gt;[\w\-]+)/$', accept_friend_request),
  </code></pre>
  
  <pre><code>{% if user.userprofile in userprofile.friends.all %}
  &lt;form&gt;
      &lt;button id="remove_friend" data-requesterid="{{user.userprofile.id}}" data-profileid="{{userprofile.id}}"&gt;
          Remove friend
      &lt;/button&gt;
  &lt;/form&gt;
  {% elif user.userprofile in userprofile.friend_requests.all %}
      Friend request pending...
  &lt;form&gt;
      &lt;button id="cancel_friend_request " data-requesterid="{{user.userprofile.id}}" data-profileid="{{userprofile.id}}"&gt;
          Cancel
      &lt;/button&gt;
  &lt;/form&gt;
  {% else %}
  &lt;form&gt;
      &lt;button id="send_friend_request" data-requesterid="{{user.userprofile.id}}" data-profileid="{{userprofile.id}}"&gt;
          Send friend request
      &lt;/button&gt;
  &lt;/form&gt;
  {% endif %}
  </code></pre>
  
  <p>I'd like the User to be able to Accept/Decline Friend Requests.</p>