Not Working condition
This commit is contained in:
parent
f96ca949f0
commit
72c6a3762d
13
posts/forms.py
Normal file
13
posts/forms.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
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)
|
@ -1,3 +1,9 @@
|
|||||||
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()
|
@ -2,5 +2,7 @@ from django.urls import path
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name = 'index')
|
path('edit', views.new, name='new'),
|
||||||
|
path('', views.index, name = 'index'),
|
||||||
|
path('delete/int:id/', views.delete, name ='delete')
|
||||||
]
|
]
|
@ -1,5 +1,31 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render, redirect, HttpResponse
|
||||||
from django.http import HttpResponse
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from .forms import NoticeForm
|
||||||
|
from .models import Notice
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return HttpResponse("Index der Seite Posts Applikation")
|
notices = Notice.objects.all()
|
||||||
|
notices.filter(pub_start__lte=timezone.now())
|
||||||
|
notices.filter(pub_start__gte=timezone.now())
|
||||||
|
context = { "notices": notices }
|
||||||
|
return render(request, 'posts/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, 'posts/edit.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
def delete(request):
|
||||||
|
notices = Notice.objects.all()
|
||||||
|
notices.filter()
|
@ -3,13 +3,9 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>My first page</title>
|
<title>My first page</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
|
||||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="jumbotron">
|
<div>
|
||||||
{% block body %} Platzhalter {% endblock body %}
|
{% block body %} Platzhalter {% endblock body %}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
10
templates/posts/edit.html
Normal file
10
templates/posts/edit.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>Neue Nachricht </h1>
|
||||||
|
<form method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit" class="save btn btn-default">Speichern</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -1,2 +1,17 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block body %} <h1> sytle="text-align:center" {{ name }} </h1> {% endblock body %}
|
|
||||||
|
{% block title %}
|
||||||
|
News
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{% for notice in notices %}
|
||||||
|
<h3> {{ notice.notice_title }}</h3>
|
||||||
|
<p> {{ notice.notice_text }}</p>
|
||||||
|
<p><a class="btn btn-info" role="button"> href={% url 'delete' id=n %} Löschen </a></p>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
|
||||||
|
{% endblock %}
|
@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
|
|||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
'posts.apps.PostsConfig',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
@ -104,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'de-de'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user