慕尼黑8549860
您好,很高兴为您解答。12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394from django.utils.translation import ugettext_lazy as _ from django import forms from django.forms.formsets import BaseFormSet from django.forms.fields import FileField from django.forms.util import ValidationError from django.shortcuts import render_to_response from django.contrib.formtools.wizard import FormWizard from ddtcms.office.equipment.models import Equipment,Characteristic,CharacteristicValue class EquipmentForm(forms.ModelForm): class Meta: model = Equipment class CharacteristicValueForm(forms.Form): def clean(self): a=self.fields s=self.data self.cleaned_data = {} # 下面的这一段for 是从 django的forms.py中的 full_clean 中复制来的 for name, field in self.fields.items(): # value_from_datadict() gets the data from the data dictionaries. # Each widget type knows how to retrieve its own data, because some # widgets split data over several HTML fields. value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name)) try: if isinstance(field, FileField): initial = self.initial.get(name, field.initial) value = field.clean(value, initial) else: value = field.clean(value) self.cleaned_data[name] = value if hasattr(self, 'clean_%s' % name): value = getattr(self, 'clean_%s' % name)() self.cleaned_data[name] = value except ValidationError, e: self._errors[name] = self.error_class(e.messages) if name in self.cleaned_data: del self.cleaned_data[name] #cl=self.cleaned_data #debug()