diff --git a/databaze/urls.py b/databaze/urls.py index 9a76f15..bf4d93d 100644 --- a/databaze/urls.py +++ b/databaze/urls.py @@ -19,5 +19,5 @@ from django.urls import path from novinky.views import index urlpatterns = [ path('admin/', admin.site.urls), - path('', index, name="index") + path('', index, name="index"), ] diff --git a/novinky/models.py b/novinky/models.py index e985592..ab019b5 100644 --- a/novinky/models.py +++ b/novinky/models.py @@ -12,5 +12,6 @@ class Novinka(models.Model): return self.titulek class Meta: + ordering = ["-datum", ] verbose_name = "Novinka" verbose_name_plural = "novinky" diff --git a/novinky/templates/novinky/base.html b/novinky/templates/novinky/base.html index e5fc4a6..23a97e6 100644 --- a/novinky/templates/novinky/base.html +++ b/novinky/templates/novinky/base.html @@ -8,7 +8,8 @@ {% block content %} - (nic tu zatim neni) +

Novinky

+ {% endblock %} \ No newline at end of file diff --git a/novinky/templates/novinky/index.html b/novinky/templates/novinky/index.html index e69de29..7fbc8ae 100644 --- a/novinky/templates/novinky/index.html +++ b/novinky/templates/novinky/index.html @@ -0,0 +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)