def __init__(self, *args, **kwargs): super(AddCard, self).__init__(*args, **kwargs) if "group" in self.data2.keys() and not self.data2['group'] == '': cat_tab_choices = Advert.get_cat_tab_choices(self.data2['group']) if "cat_tab" in self.data2.keys(): cat_type_choices = Advert.get_cat_type_choices( self.data2['group'], self.data2['cat_tab'] ) else: cat_type_choices = () else: cat_tab_choices = () cat_type_choices = () self.fields['cat_tab'] = forms.ChoiceField( choices=cat_tab_choices, # widget=StyleDropdown(value='flat'), widget=MultiChoicesHidden((StyleDropdown, HiddenInput)), ) self.fields['cat_type'] = forms.ChoiceField( choices=cat_type_choices, # widget=StyleDropdown, widget=MultiChoicesHidden((StyleDropdown, HiddenInput)), ) # for field_name, obj in self.fields.iteritems(): # self.fields[field_name].required = False self.fields['cat_tab'].required = True self.fields['cat_type'].required = True for field in ['balcony_deck','house','neighbors_in_the_apartment','parking_places','wall_material','year_built','flooring']: self.fields[field].required = False
def __init__(self, *args, **kwargs): super(Filter, self).__init__(*args, **kwargs) self.fields['cat_tab'] = forms.ChoiceField( choices=Advert.get_cat_tab_choices(self.data['group'])) self.fields['cat_type'] = forms.ChoiceField( widget=StyleDropdown, choices=Advert.get_cat_type_choices( self.data['group'], self.data['cat_tab'] ) ) # self.fields['action_type'] = forms.ChoiceField( # widget=StyleSwitch, # choices=Advert.get_action_choices() # # choices=(('rent', u'Аренда'), ('sale', u'Продажа'), ('exchange', u'Обмен')) # ) for field_name, obj in self.fields.iteritems(): self.fields[field_name].required = False