1👍
Is the intention of your getMessages(request, user)
method to get the messages for the given user?
If so, change it to this (you aren’t applying filtering since you have no arguments in the get()
call):
def getMessages(request, user):
user = User.objects.get(username=user)
messages = Message.objects.filter()
return JsonResponse({"messages":list(messages.values())})
You probably don’t need to query User model at all there though as your Message object doesn’t have a foreign key to the User table, it’s just a CharField so I assume just storing the username.
If you purpose of this method is to just get the messages for your given user then this should work:
def getMessages(request, user):
messages = Message.objects.filter(user=user)
return JsonResponse({"messages":list(messages.values())})
Source:stackexchange.com