Django Form Manager

I have a form whose length is two pages. Although the main question is asked on the first page, and based on the answer, he needs to be redirected to one of the three forms that must be filled out and then sent. I created a diagram illustrating: enter image description here

I use the django form wizard, but I don’t know exactly how to structure my mind to include this type of logic.

Can someone help me start with this? It is preferable to show some code that must be pre-generated in the form of a SessionWizardView in django format.

Thanks in advance.

+4
source share
1

get_form, , _dict, WizardView.

, urls.py WizardView, WizardView urls.py.

    def buy_cart_wizard_view_wrapper(request):

        con_dict = {FORM_ID_BILLING_ADDRESS_PICK: db_funcs.check_wizard_has_addresses_buy_cart,
                    FORM_ID_BILLING_ADDRESS: db_funcs.check_wizard_create_billing_pick_buy_cart,
                    FORM_ID_SHIPPING_ADDRESS_PICK: db_funcs.check_wizard_has_addresses_shipping_pick_buy_cart,
                    FORM_ID_SHIPPING_ADDRESS: db_funcs.check_wizard_create_shipping_pick_buy_cart,
                    FORM_ID_SAVED_BUSINESS_PAYMENT_PICK: db_funcs.check_wizard_has_payments_buy_cart,
                    FORM_ID_SAVED_BUSINESS_PAYMENT: db_funcs.check_wizard_create_payment_pick_buy_cart,
        }

        form_list = [(FORM_ID_BILLING_ADDRESS_PICK, accounts_forms.AddressPickerForm),
                 (FORM_ID_BILLING_ADDRESS, accounts_forms.BillingAddressForm),
                 (FORM_ID_SHIPPING_ADDRESS_PICK, accounts_forms.AddressPickerForm),
                 (FORM_ID_SHIPPING_ADDRESS, accounts_forms.AddressForm),
                 (FORM_ID_SAVED_BUSINESS_PAYMENT_PICK, accounts_forms.SavedBusinessPmtPickerForm),
                 (FORM_ID_SAVED_BUSINESS_PAYMENT, accounts_forms.SavedBusinessPmtBuyCartForm),
                 ]

        return BuyCartWizardView.as_view(form_list,condition_dict=con_dict, initial_dict=ini_dict)(request)

,

def check_wizard_create_payment_pick_buy_cart(wizard):
    """
    Check if the previous form has an address selected
    """
    cleaned_data = wizard.get_cleaned_data_for_step(FORM_ID_SAVED_BUSINESS_PAYMENT_PICK) or {}
    create_new_payment_ind = cleaned_data.get(FORM_FIELD_NAME) or ''
    if create_new_payment_ind != '':
        return True
    else:
        return False

True, , False, ( ).

+3

Source: https://habr.com/ru/post/1547514/


All Articles