I am trying to group messages received today, received yesterday, ect. To clarify, I'm trying to create a single headline that says “Today,” and then list these posts below. I am NOT trying to print “Today” with every message that was received that day (what is currently happening).
I currently have the TODAY and YESTERDAY headers inside the for loop, so I understand why it prints these headers for each mail message, but as said before, I just want to print them once. My question is: how can I achieve this using the following code? Do I need to do separate loops for each time period (today, yesterday, last week, ect.), Or is there a more efficient way to do this?
{% for message in messages %}
{% if message.date - current.date < 24 hours %}
TODAY
Sent by: {{ message.sender }}
{{ message.body }}
{% elif message.date - current.date > 24 hours and message.date - current.date < 48 hours %}
YESTERDAY
Sent by: {{ message.sender }}
{{ message.body }
{% endif %}
{% endfor %}
source
share