You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below is the sample code to illustrate. I picked the well-known online shop example, focusing on the checkout step, when billing and delivery addresses are specified.
>>>fromcomposite_form.formsimportCompositeForm>>>fromdjangoimportforms>>>classAddress(forms.Form):
... address=forms.CharField('address details')
...
>>>classBillingAddress(Address):
... def__init__(self, *args, **kwargs):
... kwargs['prefix'] =kwargs.get('prefix', 'billing')
... super(BillingAddress, self).__init__(*args, **kwargs)
...
>>>classDeliveryAddress(Address):
... def__init__(self, *args, **kwargs):
... kwargs['prefix'] =kwargs.get('prefix', 'delivery')
... super(DeliveryAddress, self).__init__(*args, **kwargs)
...
>>>classCheckoutAddressForm(CompositeForm):
... form_list= [BillingAddress, DeliveryAddress]
...
>>>checkout_form=CheckoutAddressForm(data={'billing-address': 'Billing Address details', 'delivery-address': 'Delivery Address details'})
>>>checkout_form.is_valid()
True>>>checkout_form.cleaned_data
{'address': u'Delivery Address details'}
>>># I would have expected two addresses with prefixes there or that __init__ failed with an error telling me same field names are not supported
The text was updated successfully, but these errors were encountered:
I've offered two alternative solutions, and you are the project owner/lead, you should decide which direction you want to take this project. Failing fast & hard is easy, supporting prefixes might lead to the land of dragons :)
Below is the sample code to illustrate. I picked the well-known online shop example, focusing on the checkout step, when billing and delivery addresses are specified.
The text was updated successfully, but these errors were encountered: