prakt 6
This commit is contained in:
parent
95498d98ef
commit
897e9e776c
@ -107,7 +107,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
LANGUAGE_CODE = 'de-de'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
|
9
djp/polls/forms.py
Normal file
9
djp/polls/forms.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django import forms
|
||||
import datetime
|
||||
|
||||
class NoticeForm(forms.Form):
|
||||
date_formats = ['%d.%m.%Y', '%d.%m.%y']
|
||||
title = forms.CharField(label='Titel', max_length=80)
|
||||
text = forms.CharField(label='Text', max_length=400)
|
||||
start = forms.DateField(label='Von', input_formats=date_formats, initial=datetime.date.today)
|
||||
end = forms.DateField(label='Bis', input_formats=date_formats, initial=datetime.date.today)
|
@ -2,6 +2,8 @@ from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index'),
|
||||
url('new', views.new, name='new'),
|
||||
]
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
import time
|
||||
from polls.forms import NoticeForm
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from polls.models import Notice
|
||||
@ -14,4 +15,13 @@ def index(request):
|
||||
# print(n.notice_title)
|
||||
return render(request, 'polls/index.html', context)
|
||||
|
||||
def new(request):
|
||||
if request.method == "POST":
|
||||
form = NoticeForm(request.POST)
|
||||
if form.is_valid():
|
||||
newNotice = Notice(notice_title=form.cleaned_data['title'],notice_text=form.cleaned_data['text'],pub_start=form.cleaned_data['start'],pub_end=form.cleaned_data['end'])
|
||||
newNotice.save()
|
||||
return redirect('index')
|
||||
context = {'form' : NoticeForm()}
|
||||
return render(request, 'polls/edit.html', context)
|
||||
# Create your views here.
|
||||
|
20
djp/templates/polls/edit.html
Normal file
20
djp/templates/polls/edit.html
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}
|
||||
edit
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<h1>Neue Nachricht</h1>
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit" class="save btn btn-default">Speichern</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,15 +4,21 @@
|
||||
Index
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div class="jumbotron jumbotron-fluid">
|
||||
<div class="container">
|
||||
<h1>Index der Polls-Applikation</h1>
|
||||
{% for post in posts %}
|
||||
<p>{{ post.notice_title }}</p>
|
||||
<p>{{ post.notice_text }}</p>
|
||||
<p>{{ post.notice_title }} {{ post.notice_text }}
|
||||
<a class="btn btn-info" role="button">delete message</a></p>
|
||||
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user