0
I want to create a view using Apiview, which shows all messages sent by a user specified in the url.
py.models:
class Message(models.Model):
body = models.CharField(max_length=500)
normaluser = models.ForeignKey(User, on_delete=models.CASCADE)
As a User I am using the User table provided by Django.
py views.:
class MessageUserView(APIView):
def get(self, request, pk): # devolve objecto
normaluser = MessageSerializer(instance=Message.objects.get(normaluser),
many=False)
serializer = MessageSerializer(instance=Message.objects.filter(pk=normaluser),
many=True)
return Response(serializer.data)
At this point in executing the code gives me the following error:
Unboundlocalerror at /website/message-user/2 local variable 'normaluser' referenced before assignment