praktikum Aufgabe5 und 6

This commit is contained in:
Nadege 2019-11-19 15:04:08 +01:00
parent eb4b3f41ee
commit dcb4c6c41e
7 changed files with 59 additions and 5 deletions

View File

@ -37,7 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'posts'
'posts.apps.PostsConfig'
]
MIDDLEWARE = [

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2.6 on 2019-11-11 14:32
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Notice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('notice_title', models.CharField(max_length=80)),
('notice_text', models.CharField(max_length=400)),
('pub_start', models.DateTimeField()),
('pub_end', models.DateTimeField()),
],
),
]

View File

@ -1,3 +1,11 @@
from django.db import models
from django.utils import timezone
# Create your models here.
class Notice(models.Model):
notice_title = models.CharField(max_length=80)
notice_text = models.CharField(max_length=400)
pub_start = models.DateTimeField(default=timezone.now)
pub_end = models.DateTimeField(default=timezone.now)

View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block content %}
<h2>Seite Infos</h2>
{% for notice in allnotice %}
<div class="notice">
<h3>{{ notice.notice_title }}</h3>
<h3>{{ notice.notice_text |linebreaks }}</h3>
</div>
{% empty %}
{% endfor %}
{% endblock %}

View File

@ -2,7 +2,7 @@ from django.urls import path
from posts import views
urlpatterns = [
path('', views.index, name='index'),
path('notice', views.index, name='index'),
path('welcome', views.welcome_seite),
path('home', views.welcome_seite),
path('about', views.about_seite)

View File

@ -1,10 +1,13 @@
from django.shortcuts import render
from django.http import HttpResponse
from datetime import datetime
from django.utils import timezone
from posts.models import Notice
# Create your views here.
def index(request):
return HttpResponse("Hello, world. You're at the posts index.")
notices = Notice.objects.all()
notices = notices.filter(pub_start__lte=timezone.now())
notices = notices.filter(pub_end__gte=timezone.now())
return render(request, 'posts/notice.html', {'allnotice': notices})
def welcome_seite(request):
return render(request, 'posts/index.html')

View File

@ -30,6 +30,9 @@
<li class="nav-item">
<a class="nav-link" href="/posts/about">about</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/posts/notice">notice</a>
</li>
</ul>
</nav>
{% endblock %}