From 299a3f660b6b11d9099048514c813cf089228ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jmeno=20P=C5=99=C3=ADjmen=C3=AD?= Date: Fri, 5 Nov 2021 09:37:50 +0100 Subject: [PATCH] =?UTF-8?q?v=C3=BDpis=20novinek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- novinky/models.py | 1 + novinky/templates/novinky/index.html | 13 +++++++++++++ novinky/views.py | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/novinky/models.py b/novinky/models.py index cb2a3ca..1ba0b4e 100644 --- a/novinky/models.py +++ b/novinky/models.py @@ -13,6 +13,7 @@ class Novinka(models.Model): return self.titulek class Meta: + ordering = ["-datum", ] verbose_name = "Novinka" verbose_name_plural = "Novinky" diff --git a/novinky/templates/novinky/index.html b/novinky/templates/novinky/index.html index e8d609d..bc121cc 100644 --- a/novinky/templates/novinky/index.html +++ b/novinky/templates/novinky/index.html @@ -1,2 +1,15 @@ {% extends "novinky/base.html" %} +{% block content %} +

Novinky

+ + {% for novinka in novinky %} +

{{ novinka.titulek }}

+ {{ novinka.autor }}
+ {{ novinka.datum }}
+

+ {{ novinka.zprava }} +

+ {% endfor %} + +{% endblock %} \ No newline at end of file diff --git a/novinky/views.py b/novinky/views.py index b2bcd5e..2427903 100644 --- a/novinky/views.py +++ b/novinky/views.py @@ -1,5 +1,12 @@ from django.shortcuts import render +from novinky.models import Novinka + + # Create your views here. def index(request): - return render(request, "novinky/index.html") + novinky = Novinka.objects.all() + context = { + "novinky": novinky, + } + return render(request, "novinky/index.html", context)