Я пытаюсь отправить данные POST из формы CBV в другой CBV.
Я использую метод valid_form, чтобы получить информацию по form.cleaned_data, а затем применяю в этом методе некоторые пользовательские методы.Но я не могу отправить результат в другое представление.
Также я попытался вставить действие в отправку html в другой шаблон, а затем получить данные, но не могу.
views.py
from django.shortcuts import render
from django.views.generic.edit import FormView
from django.views.generic.base import TemplateView
from .forms import QuoteForm
from .models import SmgQuotesTable
from .quotes import Quotes
class QuoteFormView(FormView):
template_name = 'core/home.html'
form_class = QuoteForm
success_url = 'quotes'
def form_valid(self, form):
name = form.cleaned_data['name']
email = form.cleaned_data['email']
couple = form.cleaned_data['couple']
age = form.cleaned_data['age']
kids = form.cleaned_data['kids']
#query_filter = Quotes().planSelector(couple, kids, age)
#obj = SmgQuotesTable.objects.filter(composite='Ind. Junior (H25)')
return super(QuoteFormView, self).form_valid(form)
class QuoteListView(ListView):
model = SmgQuotesTable
def get_queryset(self):
queryset = super(QuoteListView, self).get_queryset()
queryset = queryset #
print(queryset)
return queryset
home.html
{% block content %}
<style>label{display:none}</style>
<form method="post" action="{% url 'quotes-list' %}">{% csrf_token %}
{{ form.as_p }}
<input type="submit" class="btn btn-primary btn-block py-2" value="Cotizar">
</form>
{% endblock %}
urls.py
from django.urls import path
from .views import QuoteFormView, QuoteListView
urlpatterns = [
path('', QuoteFormView.as_view(), name='home'),
path('quotes/', QuoteListView.as_view(), name='quotes-list'),
]
Я ожидаю получить имя, адрес электронной почтызначения, пары, возраст и дети в QuoteView и применить метод Quotes, чтобы я мог напечатать результат в quotes.html