tildetown-admin/ttadmin/guestbook/views.py

22 lines
691 B
Python
Raw Normal View History

2016-12-20 06:00:00 +00:00
from django.shortcuts import redirect
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
from .forms import GuestbookForm
from .models import GuestbookMessage
class GuestbookView(FormView):
form_class = GuestbookForm
template_name = 'guestbook/guestbook.html'
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx['messages'] = GuestbookMessage.objects.order_by('-datetime_created')
return ctx
def form_valid(self, form):
del form.cleaned_data['captcha']
t = GuestbookMessage.objects.create(**form.cleaned_data)
return redirect('guestbook:guestbook')