Browse Source

vypis novinek

master
Pavel Škrabánek 4 years ago
parent
commit
90cd29ccec
  1. 2
      databaze/urls.py
  2. 1
      novinky/models.py
  3. 3
      novinky/templates/novinky/base.html
  4. 15
      novinky/templates/novinky/index.html
  5. 9
      novinky/views.py

2
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"),
]

1
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"

3
novinky/templates/novinky/base.html

@ -8,7 +8,8 @@
</head>
<body>
{% block content %}
(nic tu zatim neni)
<h1>Novinky</h1>
{% endblock %}
</body>
</html>

15
novinky/templates/novinky/index.html

@ -0,0 +1,15 @@
{% extends "novinky/base.html" %}
{% block content %}
<h1>Novinky</h1>
{% for novinka in novinky %}
<h2>{{ novinka.titulek }}</h2>
{{ novinka.autor }} <br>
{{ novinka.datum }} <br>
<p>
{{ novinka.zprava }}
</p>
{% endfor %}
{% endblock %}

9
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)

Loading…
Cancel
Save