Answer the question
In order to leave comments, you need to log in
How to display data grouped by dates on the page?
Good time of the day!
There is a model:
class Data(models.Model):
date_ready = models.DateField('На дату')
body = models.TextField('Задание по предмету', default='Не установлено')
subject = models.ForeignKey('Subjects', verbose_name='Предмет')
Answer the question
In order to leave comments, you need to log in
Look towards the regroup template tag - djbook.ru/rel1.8/ref/templates/builtins.html#regroup
In views.py
In templates
{% regroup data by date_ready as data_by_date %}
<ul>
{% for data in data_by_date %}
<li>{{ data.grouper }}
<ul>
{% for item in data.list %}
<li>{{ item.subject }} {{ item.body }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question