I'm using django to build a simple website and in part of it a message can be clicked on and marked as read which also pulls up a detail page with the message title and body. When I press the back button, however, it still leaves it as unread until I refresh the page. I've checked the sqlite file and it does show it as read already (I'm using a simple boolean field), but it doesn't on the page until it's refreshed.
I have tried refreshing the page to make sure that the field has the correct value, but I'm not sure where to go from here.
The section of my code that takes the user to the message detail page is as follows:
def messages(request):
user = request.user
sent_messages = Message.objects.filter(sender=user.id)
unread_messages = Message.objects.filter(recipient=user.id, read=0)
read_messages = Message.objects.filter(recipient=user.id, read=1)
context = {
'sent_messages': sent_messages,
'unread_messages': unread_messages,
'read_messages': read_messages,
}
return render(request, 'messenger/messages.html', context)
It should automatically send the message to the unread section on the page, but it won't do that unless the page is explicitly reloaded.
Aucun commentaire:
Enregistrer un commentaire