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

123456789101112131415161718192021222324252627
  1. from django.http import HttpResponse
  2. from django.shortcuts import render, redirect
  3. import time
  4. from polls.forms import NoticeForm
  5. from django.utils import timezone
  6. from datetime import timedelta
  7. from polls.models import Notice
  8. def index(request):
  9. context = {'now' : time.strftime('%H:%M:%S', time.localtime()),
  10. 'posts' : Notice.objects.all() }
  11. # start = timezone.now()
  12. #end = start + timedelta(days=10)
  13. #for n in Notice.objects.all():
  14. # print(n.notice_title)
  15. return render(request, 'polls/index.html', context)
  16. def new(request):
  17. if request.method == "POST":
  18. form = NoticeForm(request.POST)
  19. if form.is_valid():
  20. 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'])
  21. newNotice.save()
  22. return redirect('index')
  23. context = {'form' : NoticeForm()}
  24. return render(request, 'polls/edit.html', context)
  25. # Create your views here.