DataTable with support for Django Formset
DataTable is an excellent way to display tabular data, and Django Formsets are an excellent way to input tabular data -- but there seems to be no easy way to use them together. There should be a way to associate a DataTable with a Formset, so that they are both fed with the same initial data and displayed consistently.
This solves a somewhat different (but related) problem to that solved by https:/
* Input completely new data that is not kept anywhere yet until the form is submitted. An example of use case where we actually use that in Tuskar is the Resource Class creation dialog, where the user has to specify the Flavors for the new Resource Class -- since the Resource Class being created doesn't exist yet, you can't really do AJAX-based editing of data.
* Extend existing data with additional information -- for example, again in Resource Class creation dialog in Tuskar, we display a list of available Racks, with an additional column with checkboxes for selecting which Racks should be included in the newly created Resource Class.
The basic idea is that we use a mixin to DataTable, which allows us to specify the Formset class to use. The formset is created together with the DataTable instance, and populated with the data taken from the column data (the fields to be populated have to be named the same as the columns) and the POST data. Then, when the DataTable is rendered, the columns that correspond to fields from the formset have the corresponding widgets rendered instead of the plain data in them. Any validation errors are also displayed. Then you can get the Formset instance for the DataTable instance, validate it and get all the data from it.
There is also some additional (optional) JavaScript for making it easier to add and delete rows of the table.
I'm sure that this would be useful in many places in Horizon in general, not just in Tuskar, so I would like to include it.
Blueprint information
- Status:
- Complete
- Approver:
- David Lyle
- Priority:
- Medium
- Drafter:
- Radomir Dopieralski
- Direction:
- Needs approval
- Assignee:
- Radomir Dopieralski
- Definition:
- Pending Approval
- Series goal:
- Accepted for icehouse
- Implementation:
- Implemented
- Milestone target:
- 2014.1
- Started by
- Radomir Dopieralski
- Completed by
- David Lyle
Related branches
Related bugs
Sprints
Whiteboard
Gerrit topic: https:/
Addressed by: https:/
Django Formset support in DataTable
Addressed by: https:/
Configurable cell_class in DataTable