Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mailarchis/490684 to your computer and use it in GitHub Desktop.
Save mailarchis/490684 to your computer and use it in GitHub Desktop.
class AddressField(forms.MultiValueField):
"""
Custom field to take user inputs of Address
"""
def __init__(self, country_choices, city_choices, locality_choices, attrs=None):
self.widget = AddressWidget(country_choices,city_choices,locality_choices)
fields = (forms.CharField(label=_('Address Line 1'), max_length=100), forms.CharField(label=_('Address Line 2'), max_length=100), forms.ChoiceField(label=_('Country'), choices=country_choices), forms.ChoiceField(label=_('City'), choices=city_choices), forms.ChoiceField(label=_('Locality'), choices=locality_choices))
super(AddressField, self).__init__(fields, required=False)
def clean(self, value, initial=None):
value = super(AddressField, self).clean(value)
return value
def compress(self, value_list):
if value_list:
return value_list
return [[],[],[]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment