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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_treebeard_import_export-0.1.2.tar.gz.
File metadata
- Download URL: django_treebeard_import_export-0.1.2.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ae6b42040514fb8f6cfb1e35c1c0d2e5584c155a6de03c5489c63cb417ddd06
|
|
| MD5 |
facd0960130d138b105724440688fd88
|
|
| BLAKE2b-256 |
9e64bb078a48301e27c70758b02bf4a448c191972a3952776344c4e65a7efbb6
|
Provenance
The following attestation bundles were made for django_treebeard_import_export-0.1.2.tar.gz:
Publisher:
publish-pypi.yml on LlewopNomis/django-treebeard-import-export
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_treebeard_import_export-0.1.2.tar.gz -
Subject digest:
4ae6b42040514fb8f6cfb1e35c1c0d2e5584c155a6de03c5489c63cb417ddd06 - Sigstore transparency entry: 2369489182
- Sigstore integration time:
-
Permalink:
LlewopNomis/django-treebeard-import-export@4f35c4db4888a127628c1cc82caedba9e5e788e8 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/LlewopNomis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4f35c4db4888a127628c1cc82caedba9e5e788e8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_treebeard_import_export-0.1.2-py3-none-any.whl.
File metadata
- Download URL: django_treebeard_import_export-0.1.2-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddce9f6532fcce6d160a9590b5f40a8cd8899169ba0b3a25e92d3a57851f7d45
|
|
| MD5 |
6183c4e1ec5f1444931194aff42be510
|
|
| BLAKE2b-256 |
5c494e18cd358d980ad8f5c102de43881ef7326b0cac12f470ac8deecc74cfc3
|
Provenance
The following attestation bundles were made for django_treebeard_import_export-0.1.2-py3-none-any.whl:
Publisher:
publish-pypi.yml on LlewopNomis/django-treebeard-import-export
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_treebeard_import_export-0.1.2-py3-none-any.whl -
Subject digest:
ddce9f6532fcce6d160a9590b5f40a8cd8899169ba0b3a25e92d3a57851f7d45 - Sigstore transparency entry: 2369489229
- Sigstore integration time:
-
Permalink:
LlewopNomis/django-treebeard-import-export@4f35c4db4888a127628c1cc82caedba9e5e788e8 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/LlewopNomis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4f35c4db4888a127628c1cc82caedba9e5e788e8 -
Trigger Event:
release
-
Statement type: