'django.contrib.sessions', | 'django.contrib.sessions', | ||||
'django.contrib.messages', | 'django.contrib.messages', | ||||
'django.contrib.staticfiles', | 'django.contrib.staticfiles', | ||||
'polls.apps.PollsConfig', | |||||
] | ] | ||||
MIDDLEWARE = [ | MIDDLEWARE = [ | ||||
'django.middleware.security.SecurityMiddleware', | 'django.middleware.security.SecurityMiddleware', | ||||
'django.contrib.sessions.middleware.SessionMiddleware', | 'django.contrib.sessions.middleware.SessionMiddleware', | ||||
} | } | ||||
# Password validation | # Password validation | ||||
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators | # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators | ||||
# Generated by Django 2.1.3 on 2018-11-12 15:06 | |||||
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()), | |||||
], | |||||
), | |||||
] |
from django.db import models | from django.db import models | ||||
# Create your models here. | # 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() | |||||
pub_end = models.DateTimeField() |
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
import time | import time | ||||
from django.utils import timezone | |||||
from datetime import timedelta | |||||
from polls.models import Notice | |||||
def index(request): | def index(request): | ||||
context = {'now' : time.strftime('%H:%M:%S', time.localtime())} | |||||
context = {'now' : time.strftime('%H:%M:%S', time.localtime()), | |||||
'posts' : Notice.objects.all() } | |||||
# start = timezone.now() | |||||
#end = start + timedelta(days=10) | |||||
#for n in Notice.objects.all(): | |||||
# print(n.notice_title) | |||||
return render(request, 'polls/index.html', context) | return render(request, 'polls/index.html', context) | ||||
# Create your views here. | # Create your views here. |
<div class="jumbotron jumbotron-fluid"> | <div class="jumbotron jumbotron-fluid"> | ||||
<div class="container"> | <div class="container"> | ||||
<h1>Index der Polls-Applikation</h1> | <h1>Index der Polls-Applikation</h1> | ||||
{% for post in posts %} | |||||
<p>{{ post.notice_title }}</p> | |||||
<p>{{ post.notice_text }}</p> | |||||
{% endfor %} | |||||
</div> | </div> | ||||
</div> | </div> | ||||