def clean(self):
data = super(WorklistDefaultsForm, self).clean()
# this is SUPER GROSS, but apparently the only way to change the form output from here is
# to muck with the source data, by poking the undocumented _mutable property of QueryDict
self.data._mutable = True
# if no incoming data for field, fall back to default (initial) instead of empty string
for name, field in self._created_fields.items():
key = self.add_prefix(name)
value = field.widget.value_from_datadict(self.data, self.files, key)
if not value:
value = field.initial
self.data[key] = data[key] = value
self._lookup[name].default_value = value
# flip back _mutable property
self.data._mutable = False
return data
评论列表
文章目录