Export workflow
This document describes the export data workflow in detail, with hooks that enable customization of the export process.
Methods highlighted in yellow in the sequence diagram indicate public methods which can be overridden.
The export()
method retrieves a QuerySet
from the database and formats into a tablib.Dataset
.
Various hook methods are defined to allow you to customize the export data.
This is what happens when the method is invoked:
The
export()
method is passed an optional queryset parameter. Thekwargs
dict can hold additional information used to create the export, for example if called from the Admin UI.The
before_export()
hook is called.If no
QuerySet
has been passed, thenget_queryset()
method is called.The
filter_export()
hook is called. You can override this method to modify the queryset for export.For each instance in the
QuerySet
,export_resource()
is called (with the instance passed as a parameter).For each field defined in
fields
:export_field()
is called with the field and instance as parameters.If a dehydrate method is defined on the
Resource
, then this method is called to extract the field value, Otherwiseexport()
is called for each defined field, with the instance passed as a parameter.get_value()
is called with the instance to retrieve the export value from the instance.exportThe field’s widget
render()
method is called to retrieve the export value.
Each value is appended to a
tablib.Dataset
.The
tablib.Dataset
is returned fromexport()
.