diff --git a/databaze/urls.py b/databaze/urls.py index 5a1da5e..c3014a8 100644 --- a/databaze/urls.py +++ b/databaze/urls.py @@ -15,7 +15,9 @@ Including another URLconf """ from django.contrib import admin from django.urls import path +from novinky.views import index urlpatterns = [ path('admin/', admin.site.urls), + path('', index, name="index"), ] diff --git a/novinky/models.py b/novinky/models.py index 637fb6b..f7f531a 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/base.html b/novinky/templates/novinky/base.html new file mode 100644 index 0000000..d6c7cc0 --- /dev/null +++ b/novinky/templates/novinky/base.html @@ -0,0 +1,14 @@ + + + + + + + Novinky + + + {% block content %} + (nic tu nenĂ­) + {% endblock %} + + \ No newline at end of file diff --git a/novinky/templates/novinky/index.html b/novinky/templates/novinky/index.html new file mode 100644 index 0000000..8fbc324 --- /dev/null +++ b/novinky/templates/novinky/index.html @@ -0,0 +1,15 @@ +{% extends "novinky/base.html" %} + +{% block content %} +

Novinky

+ + {% for novinka in novinky %} + {{ novinka.datum }}
+ {{ novinka.autor }} +

{{ novinka.titulek }}

+

+ {{ novinka.zprava }} +

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