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 6f0488d..fcced62 100644 --- a/novinky/templates/novinky/index.html +++ b/novinky/templates/novinky/index.html @@ -1 +1,15 @@ -{% extends "novinky/base.html" %} \ No newline at end of file +{% 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 a8cbf7c..a616394 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") \ No newline at end of file + novinky = Novinka.objects.all() + context = { + "novinky": novinky, + } + return render(request, "novinky/index.html", context) \ No newline at end of file