Browse Source

praktikum Aufgabe5 und 6

master
Nadege 5 years ago
parent
commit
dcb4c6c41e

+ 1
- 1
news/settings.py View File

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

MIDDLEWARE = [

+ 24
- 0
posts/migrations/0001_initial.py 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()),
],
),
]

+ 8
- 0
posts/models.py 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)



+ 16
- 0
posts/templates/posts/notice.html 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 %}

+ 1
- 1
posts/urls.py 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)

+ 6
- 3
posts/views.py 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')

+ 3
- 0
templates/base.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 %}

Loading…
Cancel
Save