python - django 1.3 forms validation using clean method to retrieve getlist -
I have a form with checkboxes, the way the job is working, in my opinion, I request.POST.getlist ( 'List') To get a list of prices.
At the moment, I am trying to make some form validation within clean way and when I try to use myself, then '[List'] I get the final value I can not retrieve the list of items
forms.py
class SelectList_Form (forms.Form): list = forms.CharField (required) < P> = false) def clean (self): super (SelectList_Form, self). Try clean () cleaned_data = self.cleaned_data: # TODO: List validation if cleaned_data ['list'] .__len __ () is 0: form.ValidationError raise (_ ('at least one of the list below Must be selected '), if cleared_data [' list '] .__ lane (__ ()> 1: try: # here when I print the list it only shows me the last value it values me The list does not show when the box is checked cleaned_data ['list'] except main.DoesNotExist: Exclude forms, increase Http404. ValidityError: Class B Posting_Wizard (FormWizard): def render_template (self, request, form, previous_folds, phase, context = none): If the step == 0: obj = MainI18n.objects.filter (main__ is_active = true, language = request.LANGUAGE_CODE). \ Exclude (main__parent = None) .order_by ('main__parent'). Select_related (Depth = 1) category_choices = dict (['% s,% s'% (i.main.slug, i.main.parent.slug), For '% s -% s'% (i.main.parent, i.label)], I have '' ['categories'] = forms.charfield (widget = forms.RadioSelect (options = category_choices.items) in obj )) Step == 1: category = request.POST.get ('0-Categories') pobj = Main.objects.filter (slug = category.split (',') [1], original = none). Get () cobj = main.objects.filter (slug = category.split (',') [0], gravity = Pobj.id) .get () lobj = ListI18n.objects.filter (list__is_active = true language = request. LONGGUAGE_CODE, list__main__slug = category.s Plit (',') [0], list__main__parent = pobj.id) .select_related () list_choices = dict (i.id, i.title) i in lobj) cobj.mainproperties.relation == 'M': # Here I am generating checkboxes form.fields ['list'] = forms.CharField (widget = forms.CheckboxSelectMultiple (choices = list_choices.items ()), label = "select list", label, Otherwise: form.fields ['list'] = forms.CharField (widget = forms.RadioSelect (options = list_choices.items ()), label = "pick up list", return super (posting_wizard, self) .render_template (request, Form, back_fone, phase, refract ('account-registration-wizard-key Returns' get_template (self, phase): returns' listing / post / wizard / wizard_% s.html '(self, request, form_list): Return HTTP Response Redirect In the first step, there are several basic Python errors here I double There is almost never the need to reach endorsor functions - they are internal implementation details. Instead, always use the normal lane () function and, never is not for comparison: it is for identification, so only to be used with those things Those who you know about are identical identities, essentially it means none should read your code: If the LAN (cleared_data [ 'List']) == 0: etc.
Now, secondly, I do not understand why you think there might be more than one element in list . You have defined it as a CharField, which is a single field that has many characters. Your lane is testing the number of characters entered in those fields, not the number of fields, though you think you have defined them.
Comments
Post a Comment