D
D
ddgryaz2020-11-28 13:52:13
Django
ddgryaz, 2020-11-28 13:52:13

How to display items by date in Django?

There is a model:

class Handbook(models.Model):
    title = models.CharField('Наименование', max_length=250, db_index=True)
    short_title = models.CharField('Короткое наименование', max_length=100)
    description = models.TextField('Описание')
    version = models.CharField('Версия', max_length=250)  # unique=True
    date = models.DateField('Дата начала действия справочника этой версии')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'Справочник'
        verbose_name_plural = 'Справочники'

There is a view on the page in which I transfer all model objects:
def handbooks_bydate_basic(request):
    hanbooks = Handbook.objects.all()
    context = {
        'handbooks': hanbooks
    }
    return render(request, 'handbook/handbooks_bydate_basic.html', context)


The page itself:
{% extends 'handbook/basic.html' %}
{% block title %}Handbooks for date{% endblock %}
{% block content %}
<div class="features">
    <h1>Справочники по датам</h1>
    <p>Выберите дату, для отображения актуальных справочников</p>
</div>
{% endblock %}


How to implement the following: so that the user can select a date, and all directories created on this date appear to him?
Thought it would look like this:
{% for hb in handbooks %}
    {{ hb.date }}
{% endfor %}

Of course, display these objects as links, but then the same dates will be displayed if there are directories created on the same day

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question