File: export_workflow.rst

package info (click to toggle)
python-django-import-export 4.3.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,300 kB
  • sloc: python: 11,650; makefile: 180; sh: 63; javascript: 50
file content (57 lines) | stat: -rw-r--r-- 2,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
====================
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.

.. image:: _static/images/export_workflow.svg
  :alt: Export workflow sequence diagram
  :scale: 75%

The :meth:`~import_export.resources.Resource.export` method retrieves a ``QuerySet``
from the database and formats into a :class:`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 :meth:`~import_export.resources.Resource.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.

#. The :meth:`~import_export.resources.Resource.before_export` hook is called.

#. If no ``QuerySet`` has been passed, then
   :meth:`~import_export.resources.Resource.get_queryset` method is called.

#. The :meth:`~import_export.resources.Resource.filter_export` hook is called.
   You can override this method to modify the queryset for export.

#. For each instance in the ``QuerySet``,
   :meth:`~import_export.resources.Resource.export_resource` is called (with the
   instance passed as a parameter).

#. For each field defined in :attr:`~import_export.options.ResourceOptions.fields`:

   * :meth:`~import_export.resources.Resource.export_field` is called with the field and
     instance as parameters.

   * If a :ref:`dehydrate<advanced_data_manipulation_on_export>`  method is defined on
     the ``Resource``, then this method is called to extract the field value,
     Otherwise :meth:`~import_export.fields.Field.export` is called for each defined
     field, with the instance passed as a parameter.

   * :meth:`~import_export.fields.Field.get_value` is called with the instance to
     retrieve the export value from the instance.export

   * The field's widget :meth:`~import_export.widgets.Widget.render` method is called
     to retrieve the export value.

#. Each value is appended to a :class:`tablib.Dataset`.

#. The :class:`tablib.Dataset` is returned from
   :meth:`~import_export.resources.Resource.export`.