Data export¶
On this page the data_export
custom django command is described from the developer perspective.
Entry point of the data_export
command¶
When executing the data_export
command with the manage.py
management script, django searches in the app-folders of the project for a script withthe name data_export.py
lieing inside the sub-folder structure management/commands/
. Inside data_export.py
a class Command
is located, which is inherits from the django class BaseCommand
. Django expects the method handle
inside that class, which holds the execution logic for the command. Furthermore the optional method add_arguments
can be added, which adds arguments to the custom management command. Please consult the respective part of the django documentation.
The data_export
command expects as a first argument the name of the app from which structured data should be exported. That name is just the app folder name.
The handle
-method checks if a data_export.py
script is located inside the given app folder and instantiates the DataExport
class inside this file. That class holds the app specific export functionality. The most importent elements are class constants definied there. That are the MAPPING_ORM_TO_XLSX
and EXPORT_MODEL_OBJ
constant. EXPORT_MODEL_OBJ
holds the ORM-class model, from which data should be exported. MAPPING_ORM_TO_XLSX
is a mapping between the attribute names of the ORM-model and the column names of a structured data file to which it should be converted.
That means by removing key-value pairs from the dictionary it can be controlled, which attributes are exported to the data file.