Allow extra blank rows for adding new records when using list_editable in admin change list view.

210 views
Skip to first unread message

Adonys

unread,
Jan 9, 2017, 12:26:34 PM1/9/17
to Django developers (Contributions to Django itself)
This ticket #11574 is open from many years ago. I'm interested to contribute with this new feature but, if this ticket has a lot of time opened, and is very possible that there are some reservations and consideration about this feature. Before use time to build a solution, i think that will be useful discuss about this topic with the community.
Similar to `InlineModelAdmin`, I consider that this feature won't be useful for all models, is really useful for models with few fields. But, adding new records directly in the `changelist` would be util like the feature `InlineModelAdmin`, for little models. For a big model won't be impossible, but the admin form will be more usable. 
I have an idea to complete this task and is the following:
  1. Add a new attribute to the class `ModelAdmin`, to specify how many blank rows will be shown by default when the `changelist` is rendered. The new attribute would be named `list_editable_extra`, as was proposed in the ticket description. This attribute will be used basically to set as `extra` value in ModelAdmin.get_changelist_formset
  2. As was described in the ticket; "Adapt the `result_list` template tag in `admin_list.py` to show the extra forms. This can be done by calling `items_for_result` with an empty model for each empty form". I tested that suggestion and works good. 
  3. Avoid to render the `checkbox` "action-select" for the blank rows in the `changelist` action column, in order to avoid problems with changelist's actions.
  4. Add functionality similar to `InlineModelAdmin`, in order to add or to delete blank rows.
  5. Add tests for the solution, including `Selenium` tests.
  6. Add documentation about the new feature.
I evaluated 2 possibilities to reach that, both possibilities with different impact in the Django's code.
  • Render in the blank row as editable fields, only the `list_editable` fields. With this solution we need to modify less code's lines to render the blank rows. Is necessary to be clear in the documentation that this feature only will be able if the `list_editable` has been set, and could be edited only the fields added to `list_editable` tuple.
  • Render in the blank row as editable fields, all `list_display` fields. With this solution we need to make more adjusts in order to render the blank rows successfully. Is necessary to be clear in the documentation that this feature only will be able if the `list_display` has been set, and could be edited this time only the fields added to `list_display` tuple. 
I know that there are some obstacles that I will go finding in the way to reach this goal, but it's a simple resume of my idea. I'm open to better ideas.

John-Paul Jorissen

unread,
Jun 9, 2017, 10:14:57 PM6/9/17
to Django developers (Contributions to Django itself)
I would love to see this change implemented as well. I have a few models that would benefit from having a quick entryline at the bottom of the list_display. 

Personally, I think that the first possibility, where only the items that are in the 'list_editable' tuple would be editable in the  blank row makes more sense; only fields that have been designated as list editable should be editable from that view, and all others would be read-only of the default value. This would make more sense for the sake of consistency, because there may be some fields that are intentionally excluded.
Reply all
Reply to author
Forward
0 new messages