Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#270 closed defect (fixed)

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

Reported by: hugo <gb@…> Owned by: adrian
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:

Description

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 10 years ago by hugo <gb@…>

  • Summary changed from edit_inline and default on fields don't work together to Patch: 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/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:

comment:2 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(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 9 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

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