You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 1.0KB

12345678910111213141516171819202122232425262728293031
  1. from django.shortcuts import render, redirect, HttpResponse
  2. from django.utils import timezone
  3. from .forms import NoticeForm
  4. from .models import Notice
  5. def index(request):
  6. notices = Notice.objects.all()
  7. notices.filter(pub_start__lte=timezone.now())
  8. notices.filter(pub_start__gte=timezone.now())
  9. context = { "notices": notices }
  10. return render(request, 'posts/index.html', context)
  11. def new(request):
  12. if request.method == "POST":
  13. form = NoticeForm(request.POST)
  14. if form.is_valid():
  15. newNotice = Notice(notice_title=form.cleaned_data['title'],
  16. notice_text=form.cleaned_data['text'],
  17. pub_start = form.cleaned_data['start'],
  18. pub_end = form.cleaned_data['end'])
  19. newNotice.save()
  20. return redirect('index')
  21. context = {'form': NoticeForm()}
  22. return render(request, 'posts/edit.html', context)
  23. def delete(request):
  24. notices = Notice.objects.all()
  25. notices.filter()