1👍
✅
You filter on the message__sender
, so then it is expecting a User
object, or the primary key of a User
object.
You can however filter with message__sender__username=username
, the same applies for the recepient
:
def conversation_view(request, username):
messages = Message.objects.filter(
Q(message__sender__username=username) |
Q(message__recipient__username=username)
).order_by('send_time')
return render(request, "conversation.html", {
'messages': messages
})
Note: It is normally better to make use of the
settings.AUTH_USER_MODEL
[Django-doc] to refer to the user model, than to use theUser
model [Django-doc] directly. For more information you can see the referencing theUser
model section of the documentation.
Source:stackexchange.com