123456789101112131415161718192021222324252627 |
- from django.http import HttpResponse
- from django.shortcuts import render, redirect
- import time
- from polls.forms import NoticeForm
- from django.utils import timezone
- from datetime import timedelta
- from polls.models import Notice
-
- def index(request):
- context = {'now' : time.strftime('%H:%M:%S', time.localtime()),
- 'posts' : Notice.objects.all() }
- # start = timezone.now()
- #end = start + timedelta(days=10)
- #for n in Notice.objects.all():
- # print(n.notice_title)
- return render(request, 'polls/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, 'polls/edit.html', context)
- # Create your views here.
|