1

I am trying to set up a way to add friends on a social media type site, but something is wrong and I don't know what is going on.

Here is my model:

class Friend(models.Model):
    #static variables for friend_status attribute
    FORMER_FRIENDS = 0
    FRIENDS = 1
    A_REQUESTS_B = 2
    B_REQUESTS_A = 3

    friend_A = models.ForeignKey(User, related_name='friend_A')
    friend_B = models.ForeignKey(User, related_name='friend_B')
    friend_status = models.IntegerField

    def __str__(self):
        return '%s and %s friendship' % (self.friend_A, self.friend_B)

    class Meta:
        unique_together = (('friend_A', 'friend_B'),)

Here is my URL:

 url(r'^friend_request/(?P<username>[\w.@+-]+)', AddFriend.as_view(), name = 'add_friend'),

Here is my class-based view:

class AddFriend(APIView):
def get(self, request, username):
    user = Token.objects.get(key='token string').user
    friend = User.objects.get(username=username)
    #check for friendship instance
    new_friend, created = Friend.get_or_create(friend_A=user, friend_B=friend)

When I try to access the endpoint I get the following output:

DoesNotExist at /friend_request/brian
Token matching query does not exist.

Setting up friend relationships is proving more difficult than I expected. Please advise.

alexexchanges
  • 3,252
  • 4
  • 17
  • 38
Brian
  • 385
  • 1
  • 5
  • 23
  • This token not match in `Token.objects.get(key='token string')`. Where you get `token string` ?. Its exists or not ? – Ngoc Pham Dec 04 '18 at 07:11
  • Ngoc Pham, Sorry for the slow response, I just saw this. You are correct, the string 'token string' does not exist. But how do I get the correct token string? The token string is what I am trying to get from the user. I don't know it beforehand. – Brian Dec 17 '18 at 18:40

0 Answers0