Я хочу использовать форму для создания новых объектов в базе данных, но я не могу запустить это представление.Где мне нужно внести некоторые изменения?
Я пытался удалить функцию "def get", но это был только белый экран, как пустая страница после этого.
class AddOrderForm(forms.Form):
airport = forms.ChoiceField(choices=AIRPORT_CHOICES, widget=forms.RadioSelect(AIRPORT_CHOICES))
direction = forms.ChoiceField(choices=DIRECTION_CHOICES)
adress = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "Turmstraße 57"}))
client = forms.CharField()
telephone = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "+49XXXXXXXXX"}))
flight_number = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "LL 0000"}))
plane = forms.DateTimeField(input_formats=['%Y-%m-%d'])
pick_up = forms.DateTimeField(input_formats=['%Y-%m-%d'])
gate = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "G or A11"}))
driver = forms.ChoiceField(choices=DRIVER_CHOICES)
class AddOrderView(View):
def get(self, request):
form = AddOrderForm()
return render(request, 'orders/add_order.html', {'form': form})
def post(self, request, *args, **kwargs):
form = AddOrderForm(request.POST)
if form.is_valid():
order = Order.objects.create(airport=form.cleaned_data['airport'],
direction=form.cleaned_data['direction'],
adress=form.cleaned_data['adress'],
client=form.cleaned_data['client'],
telephone=form.cleaned_data['telephone'],
flight_number=form.cleaned_data['flight_number'],
plane=form.cleaned_data['plane'],
pick_up=form.cleaned_data['pick_up'],
gate=form.cleaned_data['gate'],
driver=form.cleaned_data['driver'])
return redirect(f'order/{order.id}')
return render(request, 'orders/add_order.html', {'form': form})