Hi, I try to follow the documentation, but I can’t see a formula on my site. Any ideas where I do my mistake?
Regards
Georg
**forms.py**
from django import forms
import datetime
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
class BookingForm(forms.Form):
belegdatum = forms.DateField(label='Belegdatum')
buchungstext = forms.CharField(label='Buchungstext')
betrag = forms.CharField(label='Betrag')
def clean_date(self):
if data < datetime.date.today():
raise ValidationError(_('Ungültig - Datum in der Vergangenheit'))
if data > datetime.date.today():
raise ValidationError(_('Ungültig - Datum in der Zukunft'))
return data
**views.py**
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from .models import Cashier, Booking
from .forms import BookingForm
def get_booking(request):
if request.method == 'POST':
form = BookingForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/thanks/')
else:
form = BookingForm()
return render(request, 'booking.html', {'form': form})
def index(request):
context = {'cashiers': Cashier.objects.all(), 'titel': 'Kassierer'}
return render(request=request, template_name='../templates/index.html', context=context)
def booking(request, slug):
context = {'bookings': Booking.objects.all(), 'titel': 'Buchungsmaske'}
return render(request=request, template_name='../templates/booking.html', context=context)
**booking.html**
{% extends 'base.html' %}
{% block content %}
<h1>{{ titel }}</h1>
<form method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Buchen">
</form>
{% endblock %}