praktikum Aufgabe5 und 6
This commit is contained in:
parent
eb4b3f41ee
commit
dcb4c6c41e
@ -37,7 +37,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'posts'
|
||||
'posts.apps.PostsConfig'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
24
posts/migrations/0001_initial.py
Normal file
24
posts/migrations/0001_initial.py
Normal 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()),
|
||||
],
|
||||
),
|
||||
]
|
@ -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)
|
||||
|
||||
|
||||
|
16
posts/templates/posts/notice.html
Normal file
16
posts/templates/posts/notice.html
Normal 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 %}
|
@ -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)
|
||||
|
@ -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')
|
||||
|
@ -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 %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user