from django.shortcuts import render, redirect from datetime import timedelta from django.utils import timezone from posts.models import Notice from posts.forms import NoticeForm from django.http import HttpResponse # Create your views here. #Titel und die Texte aller Meldungen, deren Veröffentlichungsdatum vor und der Endedatum nach dem aktuellen Datum liegt. def home(request, value=""): now = timezone.now() notices = Notice.objects.all() display_notices = list() for notice in notices: if notice.pub_start < now and notice.pub_end > now: display_notices.append(notice) context = { "title": "Beboop", "notices": display_notices } return render(request, '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, 'edit.html', context) def delete(request, value): notice = Notice.objects.get(id = value) notice.delete() return redirect('index')