Answer the question
In order to leave comments, you need to log in
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 = 'Справочники'
def handbooks_bydate_basic(request):
hanbooks = Handbook.objects.all()
context = {
'handbooks': hanbooks
}
return render(request, 'handbook/handbooks_bydate_basic.html', context)
{% extends 'handbook/basic.html' %}
{% block title %}Handbooks for date{% endblock %}
{% block content %}
<div class="features">
<h1>Справочники по датам</h1>
<p>Выберите дату, для отображения актуальных справочников</p>
</div>
{% endblock %}
{% for hb in handbooks %}
{{ hb.date }}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question