Patch: edit_inline and default on fields don't work together
The empty lines in the edit_inline table (I am using the TABULAR format) don't work nicely together - the empty fields are not set to default values when I define those in the models. Either the system should use the default values when a field that can't be blank is passed in as blank or it should initialize the field to the default values (the latter being more consistent I think). At the moment you will get SQL exceptions if you don't enter data for new lines where fields are defined as NOT NULL in the database.
Change History
(3)
| Summary: |
edit_inline and default on fields don't work together → Patch: edit_inline and default on fields don't work together
|
| Resolution: |
→ fixed
|
| Status: |
new → closed
|
checked a bit more on this one: it only happens with the num_extra_on_change lines when editing an existing object with a related list of objects that are edited inline in tabular form. If I add a new object, default is set accordingly. Only the additional empty lines on edit are missing the default value. I have a patch to solve the problem: this one will populate a field_default based on the field we are looking at.
Index: views/admin/main.py =================================================================== --- views/admin/main.py (revision 416) +++ views/admin/main.py (working copy) @@ -942,7 +942,10 @@ if f.editable and f != rel_field: for field_name in f.get_manipulator_field_names(''): full_field_name = '%s.%d.%s' % (var_name, i, field_name) - collection[field_name] = formfields.FormFieldWrapper(manipulator[full_field_name], new_data.get(full_field_name, ''), errors.get(full_field_name, [])) + field_default = '' + if f.has_default(): + field_default = f.get_default() + collection[field_name] = formfields.FormFieldWrapper(manipulator[full_field_name], new_data.get(full_field_name, field_default), errors.get(full_field_name, [])) wrapper.append(formfields.FormFieldCollection(collection)) setattr(form, rel_opts.module_name, wrapper) if rel_opts.order_with_respect_to and rel_opts.order_with_respect_to.rel and rel_opts.order_with_respect_to.rel.to == opts: