Hello. We are sorry but we cannot help you. This mailing list is to work on developing Python (adding new features to Python itself and fixing bugs); if you're having problems learning, understanding or using Python, please find another forum. Probably python-list/comp.lang.python mailing list/news group is the best place; there are Python developers who participate in it; you may get a faster, and probably more complete, answer there. See http://www.python.org/community/ for other lists/news groups/fora. Thank you for understanding.
On Thu, Oct 20, 2011 at 06:51:05PM +0000, Asif Jamadar wrote: > So I'm trying to generate dynamic choices for django form. Here i'm usig > formset concept (CODE is mentioned below) > > > > Suppose i have list called criteria_list = ['education', 'know how', > 'managerial', 'interpersonal', ] > > > > now i need to generate choices as follows > > > > list1 = [('education', 1), ('education', 2), ('education', 3), (''education' > , 4) , ('know how', 1) ('know ho', 2), ('know ho', 3), ('know ho', 4)] > > > > list2 = [('education', 1), ('education', 2), ('education', 3), (''education' > , 4) , ('managerial', 1) ('managerial', 2), ('managerial', 3), ('managerial', > 4)] > > > > list3 = [('education', 1), ('education', 2), ('education', 3), (''education' > , 4) , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3), > ('interpersonal', 4)] > > > > list4 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' , 4) > , ('managerial', 1) ('managerial', 2), ('managerial', 3), ('managerial', 4)] > > > > list5 = [('know how', 1), ('know how', 2), ('know how ', 3), ('know how' , 4) > , ('interpersonal', 1) ('interpersonal', 2), ('interpersonal', 3), > ('interpersonal', 4)] > > > > list6= [('managerial', 1), ('managerial', 2), ('managerial ', 3), > ('managerial' , 4) , ('interpersonal', 1) ('interpersonal', 2), > ('interpersonal', 3), ('interpersonal', 4)] > > > > > > How can i achive this in python? > > > > The above all eachh list become the choices for each form. > > > > Suppose i have formset of 6 forms. Then how can i assign above dynamic > generates list to the choice field of each form. > > > > I tried by using this following code but no luck > > > > > > view.py > > > > def evaluation(request): > > > > evaluation_formset = formset_factory(EvaluationForm, > formset=BaseEvaluationFormset, extra=6) > > > > if request.POST: > > > > formset = evaluation_formset(request.POST) > > > > ##validation and save > > > > else: > > > > formset = evaluation_formset() > > > > render_to_response(formset) > > > > forms.py > > > > > > class EvaluationForm(forms.Form): > > > > value = > forms.ChoiceField(widget=forms.RadioSelect(renderer=HorizontalRadioRenderer)) > > > > class BaseEvaluationFormSet(BaseFormSet): > > def __init__(self, *args, **kwargs): > > super(BaseEvaluationFormSet, self).__init__(*args, **kwargs) > > for form_index, form in enumerate(self.forms): > > > > form.fields["value"].choices = self.choice_method(form_index) > > def choice_method(self, form_index): > > list = [] > > item_list = [] > > criteria_list = [] > > criteria_length = len(sub_criterias)-1 > > for criteria_index in range(criteria_length): > > counter = 1 > > if criteria_index == form_index: > > for j in range(criteria_length-counter): > x = 1 > for i in range(6): > criteria_list.append((sub_criterias[criteria_index], > sub_criterias[criteria_index])) > > item_list.append((sub_criterias[criteria_index+ 1], > sub_criterias[criteria_index+1])) > > list = criteria_list +item_list > > counter = counter + 1 > if x != criteria_length: > > x = x + 1 > > > > return list > > > > > > > > > > > > > > > > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/phd%40phdru.name Oleg. -- Oleg Broytman http://phdru.name/ p...@phdru.name Programmers don't die, they just GOSUB without RETURN. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com