DataTable with support for Django Formset

Registered by Radomir Dopieralski

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 and which allow you to edit an existing data table. With a Formset-enabled data table you can do more:

* 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

David Lyle
Radomir Dopieralski
Needs approval
Radomir Dopieralski
Pending Approval
Series goal:
Accepted for icehouse
Milestone target:
milestone icon 2014.1
Started by
Radomir Dopieralski
Completed by
David Lyle

Related branches



Gerrit topic:,topic:bp/formset-data-table,n,z

Addressed by:
    Django Formset support in DataTable

Addressed by:
    Configurable cell_class in DataTable


Work Items

This blueprint contains Public information 
Everyone can see this information.


No subscribers.