Token matching query does not exist

408 Views Asked by At

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.

0

There are 0 best solutions below