-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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.
>>> from composite_form.forms import CompositeForm
>>> from django import forms
>>> class Address(forms.Form):
... address = forms.CharField('address details')
...
>>> class BillingAddress(Address):
... def __init__(self, *args, **kwargs):
... kwargs['prefix'] = kwargs.get('prefix', 'billing')
... super(BillingAddress, self).__init__(*args, **kwargs)
...
>>> class DeliveryAddress(Address):
... def __init__(self, *args, **kwargs):
... kwargs['prefix'] = kwargs.get('prefix', 'delivery')
... super(DeliveryAddress, self).__init__(*args, **kwargs)
...
>>> class CheckoutAddressForm(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 supportedReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels