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.

Export workflow sequence diagram

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:

  1. The export() method is passed an optional queryset parameter. The kwargs dict can hold additional information used to create the export, for example if called from the Admin UI.

  2. The before_export() hook is called.

  3. If no QuerySet has been passed, then get_queryset() method is called.

  4. The filter_export() hook is called. You can override this method to modify the queryset for export.

  5. For each instance in the QuerySet, export_resource() is called (with the instance passed as a parameter).

  6. 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, Otherwise export() 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.export

    • The field’s widget render() method is called to retrieve the export value.

  7. Each value is appended to a tablib.Dataset.

  8. The tablib.Dataset is returned from export().