Browse Source

výpis novinek

master
Jméno Příjmení 4 years ago
parent
commit
6a7cf18f28
  1. 2
      databaze/urls.py
  2. 1
      novinky/models.py
  3. 14
      novinky/templates/novinky/base.html
  4. 15
      novinky/templates/novinky/index.html
  5. 7
      novinky/views.py

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

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

14
novinky/templates/novinky/base.html

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Novinky</title>
</head>
<body>
{% block content %}
(nic tu není)
{% 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 %}
{{ novinka.datum }} <br>
{{ novinka.autor }}
<h2>{{ novinka.titulek }}</h2>
<p>
{{ novinka.zprava }}
</p>
{% endfor %}
{% endblock %}

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

Loading…
Cancel
Save