0

我正在创建一个 Django 多向导表单。我需要通过发布请求将数据发送到已经创建的视图这是向导表单:

class UserQueryWizard(SessionWizardView):

template_name = "wizards/index.html"
form_list = [forms.ShippingForm,
             forms.ExporterdetailsForm, forms.ImporterdetailsForm, ]

def done(self, form_list, **kwargs):
    post_data = [form.cleaned_data for form in form_list]
    ------need to send this post_data ------
    return SEND('query/',method='POST') <--- Example I know its not correct its ruff idea what I want 

我设置了这样的 URL:

path('query/', views.UserQueryView.as_view(), name='user_query'),<--- Where i send POST Request

和视图

class UserQueryView(View):
 def post(self, request, *args, **kwargs):
    importer = request.POST.get('importer', '')
    .......etc......................

    
    query = UserQuery.objects.create(
        make=make, model=model, version=version, launch_date=launch_date,
        body_type=body_type, importer_type=importer_type, vehicle_condition=condition,
        mileage=mileage, chasis_number=chasis_number, engine_number=engine_number,
        fuel_type=fuel_type, vehicle_color=vehicle_color,
        seating_position=seating_position, importer=importer, importer_country=importer_country, 
        importer_city=importer_city,
        importer_name=importer_name, exporter_name=exporter_name, exporter=exporter, 
        exporter_country=exporter_country, exporter_city=exporter_city,
        hs_code=hs_code
    )

    result = render_to_string(
        'partials/_alert.html', {"type": "success", "message": "Query Saved Successfully"}, request=request)

    query = render_to_string(
        'partials/_table_row.html', {'vehicle': query}, request=request)

    return JsonResponse({"message": result, 'query': query})
4

0 回答 0