Empty cleaned_data dict when using custom dictionary made of request.POST for Django formset -
i data post request. want make changes data , pass formset. function:
def add_report(request, project): if request.method == 'post': data = dict(copy.deepcopy(request.post)) del data['media_url'], data['save_reports'] data['document_type'] = map(lambda x, y: x or y, data['document_type'], data['document_type_other']) data['paid_at'] = zip(data['day'], data['month'], data['date-year']) data['paid_at'] = map(lambda x: get_paid_at_date(x), data['paid_at']) del data['document_type_other'], data['day'], data['month'], data['date-year'] qdict = querydict('', mutable=true) qdict.update(data) max_num = len(request.post['description']) media = request.post.get('report_file') qdict['form-total_forms'] = max_num qdict['form-initial_forms'] = u'0' qdict['form-max_num_forms'] = u'' reportformset = formset_factory(form=documentcreateform) formset = reportformset(qdict) form_number, form in enumerate(formset): if form.is_valid(): print ("form.cleaned_data", form.cleaned_data) # after want fields , save object
the form valid cleaned_data empty dictionary. documentcreateform:
class documentcreateform(forms.modelform): document_type = forms.choicefield(widget=forms.select(), choices=document.document_choices) report_file = forms.charfield(required=false, widget=forms.hiddeninput) class meta: model = document fields = ('amount', 'paid_at', 'description', 'document_type',) def clean_document_type(self): document_type = self.cleaned_data.get('document_type') if document_type: return document_type raise forms.validationerror("this field required", code='required')
do have idea doing wrong , how can fix this? lot in advance! p.s. i've found similar questions didn't help.
Comments
Post a Comment