A
A
almenovr2021-06-11 09:49:05
Django
almenovr, 2021-06-11 09:49:05

How to store form data in database?

I do by analogy with adding comments, nothing happens. Where is the mistake?

index.html

<form method="post" action="{% url 'create_order' %}">
                                            {% csrf_token %}
                      <div class="row">
                        <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Ваше имя</label>
                                                    <input type="text" name="phoneNumber" placeholder="Ваше имя" required>
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Ваш телефон</label>
                                                    <input type="text" name="phoneNumber" placeholder="Номер телеофна" required>
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Дата</label>
                                                    <input type="date" name="date" placeholder="Дата прилета" >
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Время</label>
                                                    <input type="time" name="time" placeholder="Время прилета" >
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Номер рейса</label>
                                                    <input type="text" name="flightNumber" placeholder="Номер рейса или поезда" required>
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Количество пассажиров</label>
                                                    <input type="text" name="numberPassengers" placeholder="Количество" required>
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Откуда</label>
                                                    <input type="text" name="cityFrom" placeholder="Откуда" required>
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                                                    <label>Куда</label>
                                                    <input type="text" name="cityWhere" placeholder="Куда" required>
                                                </div>
                                                <div class="form-group col-lg-6 col-md-6 col-sm-12">
                          <label>Класс автомобиля</label>
                          <select class="custom-select-box">
                            <option>Эконом</option>
                                                        <option>Стандарт</option>
                            <option>Комфорт</option>
                            <option>Бизнес</option>
                            <option>Минивен</option>
                          </select>
                        </div>
                        <div class="form-group col-lg-12 col-md-12 col-sm-12">
                          <button type="submit" class="theme-btn btn-style-two"><span class="txt">Заказать</span></button>
                        </div>
                      </div>
                    </form>


forms.py

class OrderForm(forms.ModelForm):
    """Форма отзывов"""
    class Meta:
        model = Orders
        fields = ("name", "phoneNumber", "date", "time", "flightNumber", "numberPassengers",
                  "cityFrom", "cityWhere", "carClass")


urls.py

urlpatterns = [
    path('', views.DirectionView.as_view()),
    path('<slug:slug>/', views.DirectionDetailView.as_view()),
    path('review/<int:pk>/', views.AddReview.as_view(), name="add_review"),
    path('order/', views.CreateOrder.as_view(), name='create_order'),
]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question