Not Working condition
This commit is contained in:
@@ -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
|
||||
|
||||
# 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()
|
||||
+3
-1
@@ -2,5 +2,7 @@ from django.urls import path
|
||||
from . import views
|
||||
|
||||
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')
|
||||
]
|
||||
+29
-3
@@ -1,5 +1,31 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render, redirect, HttpResponse
|
||||
from django.utils import timezone
|
||||
|
||||
from .forms import NoticeForm
|
||||
from .models import Notice
|
||||
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user