For a full solution, you need to query the value of each field. You can do this with .value() on an instantiated form. So you can instantiate a dummy form, and then go through the bound fields, calling .value() on them and then using that as data, something this:
dummy_form = ...
default_values = {} for bound_field in dummy_form: v = bound_field.value() if v is not None: default_values[bound_field.name] = v
Then
SomeForm(default_values)
I think this works because the fields check the type of their input before cleaning. It's not exactly elegant, though, forms in Django are a bit rough around the edges.
Comment
For a full solution, you need to query the value of each field. You can do this with .value() on an instantiated form. So you can instantiate a dummy form, and then go through the bound fields, calling .value() on them and then using that as data, something this:
dummy_form = ...
default_values = {}
for bound_field in dummy_form:
v = bound_field.value()
if v is not None:
default_values[bound_field.name] = v
Then
SomeForm(default_values)
I think this works because the fields check the type of their input before cleaning. It's not exactly elegant, though, forms in Django are a bit rough around the edges.
Replies
This works, thx