django-treebeard-import-export
A Django app that generates Excel (.xlsx) import templates for another app's models —
including dropdown validation for foreign keys, choices, booleans, and django-treebeard
MP_Node parent fields — then reads a filled-in workbook back into the database.
It also supports the reverse direction: populating a freshly generated template with the current contents of the database, so you get an editable export/snapshot in the same shape the importer expects.
How it works
create_import_template <app_label>builds one worksheet per model in the target app, with a table, column headers, and Excel data-validation dropdowns for FK/choice/boolean fields. Foreign keys are resolved by the related model's natural key (oremailfor the user model) rather than by primary key.populate_import_workbook <app_label>fills that template with the app's current database rows, so it can be used as an export or as a starting point for edits.import_workbook <app_label>reads a filled-in workbook back and creates/updates rows, resolving foreign keys and choice fields, and handlingMP_Nodeparentcolumns by natural key rather than tree position.
Files are read from and written to a fixed location so the two commands chain without file arguments:
<target_app>/media/data_exchange/import_templates/<app_label>_import_template.xlsx
<target_app>/media/data_exchange/import_files/<app_label>_import_file.xlsx
A model can opt out of templating entirely with EXCLUDE_FROM_IMPORT_TEMPLATE = True.
Requirements
This is a self-contained, pip-installable Django app — every internal import is a
relative import within the data_exchange package (no coupling to a specific host
project layout), and dependencies are declared in pyproject.toml: django,
django-treebeard, django-allauth, openpyxl.
django-allauth is required because the optional --include-users worksheet records a
new user's email via allauth.account.models.EmailAddress.
Any model you want a template for must implement get_by_natural_key() on its manager
(standard Django) — this is how the importer/exporter resolve and reconstruct foreign
keys without relying on primary keys.
Installation
-
Install the package into your Django project's environment. Until this is published to PyPI, install it directly from GitHub or as an editable local checkout:
pip install git+https://github.com/LlewopNomis/django-treebeard-import-export.git@v0.1.0 # or, for local development: pip install -e /path/to/django-treebeard-import-export
-
Add it to
INSTALLED_APPS:INSTALLED_APPS = [ ... "data_exchange", ]
Usage
Generate a template for an app's models:
python manage.py create_import_template <app_label>
# Include a "User" worksheet (matched by email) for models with a user FK
python manage.py create_import_template <app_label> --include-users
Fill that template with the app's current database contents:
python manage.py populate_import_workbook <app_label>
# List which models would be populated, without touching the database
python manage.py populate_import_workbook <app_label> --list-models
# Only populate specific models, or populate everything except some
python manage.py populate_import_workbook <app_label> --only-model=Account,Organisation
python manage.py populate_import_workbook <app_label> --skip-model=FinancialData
Edit the workbook (in <app_label>/media/data_exchange/import_files/), then import it:
python manage.py import_workbook <app_label>
The importer reports successes, failures, and timing per model to stdout.
Development
The test suite doesn't depend on a host project. tests/ ships a minimal Django
settings module (tests/settings.py) and a throwaway tests/testapp with sample models
(plain fields, an FK, a compound-natural-key FK, choices, a boolean, and an MP_Node
tree) that exist only to exercise data_exchange end to end - neither is included in the
installed package (see [tool.setuptools.packages.find] in pyproject.toml).
python -m venv .venv
source .venv/bin/activate
pip install -e ".[test]"
pytest
License
MIT — see LICENSE.
Metadata
Release files for django-treebeard-import-export 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_treebeard_import_export-0.1.2.tar.gz | 22.5 kB | With provenance | Details for django_treebeard_import_export-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_treebeard_import_export-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for django_treebeard_import_export-0.1.2-py3-none-any.whl |
Total release size: 49.2 kB
Release files / django_treebeard_import_export-0.1.2.tar.gz
| Download URL | django_treebeard_import_export-0.1.2.tar.gz |
|---|---|
| Size | 22.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ae6b42040514fb8f6cfb1e35c1c0d2e5584c155a6de03c5489c63cb417ddd06
|
|
BLAKE2b-256 checksum How to use checksums |
9e64bb078a48301e27c70758b02bf4a448c191972a3952776344c4e65a7efbb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / django_treebeard_import_export-0.1.2-py3-none-any.whl
| Download URL | django_treebeard_import_export-0.1.2-py3-none-any.whl |
|---|---|
| Size | 26.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ddce9f6532fcce6d160a9590b5f40a8cd8899169ba0b3a25e92d3a57851f7d45
|
|
BLAKE2b-256 checksum How to use checksums |
5c494e18cd358d980ad8f5c102de43881ef7326b0cac12f470ac8deecc74cfc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logSecurity for django-treebeard-import-export 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_treebeard_import_export-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.