Why
Utilities for loading and dumping database data as JSON.
These utilities (partially) replace Django’s built-in dumpdata and loaddata management commands.
Suppose you want to move data between systems incrementally. In this case it isn’t sufficient to only know the data which has been created or updated; you also want to know which data has been deleted in the meantime. Django’s dumpdata and loaddata management commands only support the former case, not the latter. They also do not including dependent objects in the dump.
This package offers utilities and management commands to address these shortcomings.
How
pip install feincms3-data.
Add feincms3_data to INSTALLED_APPS so that the included management commands are discovered.
Add datasets somewhere describing the models and relationships you want to dump, e.g. in a module named app.f3datasets:
from feincms3_data.data import (
specs_for_app_models,
specs_for_derived_models,
specs_for_models,
)
from app.dashboard import models as dashboard_models
from app.world import models as world_models
def districts(args):
pks = [int(arg) for arg in args.split(",") if arg]
return [
*specs_for_models(
[world_models.District],
{
"filter": {"pk__in": pks},
"delete_missing": True,
},
),
*specs_for_models(
[world_models.Exercise],
{
"filter": {"district__in": pks},
"delete_missing": True,
},
),
# All derived non-abstract models which aren't proxies:
*specs_for_derived_models(
world_models.ExercisePlugin,
{
"filter": {"parent__district__in": pks},
"delete_missing": True,
},
),
]
def datasets():
return {
"articles": {
"specs": lambda args: specs_for_app_models(
"articles",
{"delete_missing": True},
),
},
"pages": {
"specs": lambda args: specs_for_app_models(
"pages",
{"delete_missing": True},
),
},
"teachingmaterials": {
"specs": lambda args: specs_for_models(
[
dashboard_models.TeachingMaterialGroup,
dashboard_models.TeachingMaterial,
],
{"delete_missing": True},
),
},
"districts": {
"specs": districts,
},
}
Add a setting with the Python module path to the specs function:
FEINCMS3_DATA_DATASETS = "app.f3datasets.datasets"
Now, to dump e.g. pages you would run:
./manage.py f3dumpdata pages > tmp/pages.json
To dump the districts with the primary key of 42 and 43 you would run:
./manage.py f3dumpdata districts:42,43 > tmp/districts.json
The resulting JSON file has three top-level keys:
"version": 1: The version of the dump, because not versioning dumps is a recipe for pain down the road.
"specs": [...]: A list of model specs.
"objects": [...]: A list of model instances; uses the same serializer as Django’s dumpdata, everything looks the same.
Model specs consist of the following fields:
"model": The lowercased label (app_label.model_name) of a model.
"filter": A dictionary which can be passed to the .filter() queryset method as keyword arguments; used for determining the objects to dump and the objects to remove after loading.
"delete_missing": This flag makes the loader delete all objects matching "filter" which do not exist in the dump. Those objects whose deletion is a precondition for loading the dump at all – because they hold unique values which an object from the dump is claiming – are deleted before loading instead of at the end. Nothing else changes: the very same objects are deleted, only earlier.
"ignore_missing_m2m": A list of field names where deletions of related models should be ignored when restoring. This may be especially useful when only transferring content partially between databases.
"save_as_new": If present and truish, objects are inserted using new primary keys into the database instead of (potentially) overwriting pre-existing objects.
"defer_values": A list of fields which should receive random garbage when loading initially and only receive their real value later. This is especially useful to avoid unique constraint errors when loading partial graphs.
The dumps can be loaded back into the database by running:
./manage.py f3loaddata -v2 tmp/pages.json tmp/districts.json
Each dump is processed in an individual transaction. The data is first loaded into the database; at the end, data matching the filters but whose primary key wasn’t contained in the dump is deleted from the database (if "delete_missing": True). The only exception are objects holding unique values which the dump’s data claims – those are removed upfront, since databases do not allow the old and the new row to exist at the same time.
Both deletions are restricted to the spec’s "filter". An object outside of the filter which holds a unique value claimed by the dump therefore still makes the load fail; widen the filter (or dump fewer objects) in that case.
Release files for feincms3-data 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| feincms3_data-0.11.0.tar.gz | 23.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| feincms3_data-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.2 kB
Release files / feincms3_data-0.11.0.tar.gz
| Download URL | feincms3_data-0.11.0.tar.gz |
|---|---|
| Size | 23.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65a961d303711307b61bec919e4a0c4cca074b1822d8d8e56e0e6035e4514abb
|
|
BLAKE2b-256 checksum How to use checksums |
992a3e40c05644e0ef6853825586c9bb3b3232c82fc0df74347748474ca1ec20
|
| 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 25, 2026.
Transparency logRelease files / feincms3_data-0.11.0-py3-none-any.whl
| Download URL | feincms3_data-0.11.0-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d73489268d513ac4ace943fe366b226e80781d33bead4eb5878a1af4d9d9a701
|
|
BLAKE2b-256 checksum How to use checksums |
042710d7818e2de031f98502639cf87fbdcd9362475fec7add7823e5227a5543
|
| 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 25, 2026.
Transparency log