Created
July 26, 2010 15:16
-
-
Save mailarchis/490684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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