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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
Django Management Commands
==========================
Export Command
--------------
The ``export`` command allows you to export data from a specified Django model
or a resource class. The exported data can be saved in different formats, such
as CSV or XLSX.
Usage
-----
.. code-block:: bash
python manage.py export <format> <resource> [--encoding ENCODING]
- **format**: Specify the format in which the data should be exported. -
- **resource**: Specify the resource or model to export. Accepts a resource class or a model class in dotted path format. - **--encoding** (optional): Specify the encoding (e.g., 'utf-8') to be used for the exported data.
Example
-------
.. code-block:: bash
python manage.py export CSV auth.User
This command will export the User model data in CSV format using utf-8
encoding.
Another example:
.. code-block:: bash
python manage.py export XLSX mymodule.resources.MyResource
This command will export the data from ``MyResource`` resource in XLSX format.
Import Command
--------------
The ``import`` command allows you to import data from a file using a specified
Django model or a custom resource class.
Usage
-----
.. code-block:: bash
python manage.py import <resource> <import_file_name> [--format FORMAT] [--encoding ENCODING] [--dry-run] [--raise-errors]
- **resource**: The resource class or model class in dotted path format.
- **import_file_name**: The file from which data is imported (``-`` can be used to indicate stdin).
- **--format** (optional): Specify the format of the data to import. If not provided, it will be guessed from the mimetype.
- **--encoding** (optional): Specify the character encoding of the data.
- **--dry-run**: Perform a trial run without making changes.
- **--raise-errors**: Raise any encountered errors during execution.
Example
-------
Import data from file into auth.User model using default model resource:
.. code-block:: bash
python manage.py import auth.User users.csv
Import data from file using custom model resource, raising errors:
.. code-block:: bash
python manage.py import --raise-errors helper.MyUserResource users.csv
|