Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#270 closed defect (fixed)

Patch: edit_inline and default on fields don't work together

Reported by: hugo <gb@…> Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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)

comment:1 Changed 13 years ago by hugo <gb@…>

Summary: edit_inline and default on fields don't work togetherPatch: edit_inline and default on fields don't work together

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/
--- views/admin/ (revision 416)
+++ views/admin/ (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, []))
         setattr(form, rel_opts.module_name, wrapper)
         if rel_opts.order_with_respect_to and rel_opts.order_with_respect_to.rel and == opts:

comment:2 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [418]) Fixed #270 -- Admin change forms now display default values in num_extra_on_change fields with default set. Thanks for the patch, Hugo

comment:3 Changed 11 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top