I am trying to make a friend request class-based-view work on a django project, but keep getting errors. The error I am currently getting is: TypeError at /friend_request/joe int() argument must be a string, a bytes-like object or a number, not 'User'
My Friend model is not looking for an int() though, so I am unsure of what is going on.
class-based view:
class AddFriend(APIView):
def get(self, request, username):
friend = User.objects.get(username=username)
current_user = request.user.username
f = Friend(current_user, friend, 1)
f.save()
url:
url(r'^friend_request/(?P<username>[\w.@+-]+)', AddFriend.as_view(), name = 'add_friend'),
model:
class Friend(models.Model):
#static variables for friend_status attribute
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'),)
Ideally this CBV would figure out who the user sending the request is, figre out what friend is being "looked up" in the url, and create/save a new friend instantiation. Where is this int() error coming from, and how do I fix it?