Content Block Template Export and Import#
Exporting and importing ContentBlockTemplate allows reuse of your ContentBlockTemplate in other projects.
Note
When moving ContentBlockTemplate to a project you will also need to provide any required html templates and static files.
Natural Keys#
Natural keys are used when serializing and deserializing. ContentBlockTemplate are referenced by their name and ContentBlockTemplateField are additionally referenced by their key.
This becomes important when importing when there are existing ContentBlockTemplate. Any ContentBlockTemplate with the same name will be updated as will child ContentBlockTemplateField with the same key.
Note
If the key changes for any ContentBlockTemplateField then it will be deleted and a new ContentBlockTemplateField with the new key will be created.
Warning
Any ContentBlockTemplateField which has been added or removed from the parent ContentBlockTemplate will be added or removed from ContentBlock. Due to this data can be lost in published ContentBlock and care must be taken when working with production data.
You can read more about natural keys in the official Django documentation.
Exporting#
The export_content_block_templates management command will serialize all ContentBlockTemplate to JSON and output to stdout. Output can be directed to a file:
$ python3 manage.py export_content_block_templates > content_block_templates.json
A button is provided on the ContentBlockTemplate admin changelist page which will serialize all ContentBlockTemplate and provide a JSON file for download.
An admin action is available such that you can choose which ContentBlockTemplate to export.
Importing#
The import_content_block_templates management command takes a single argument for the JSON file location.
$ python3 manage.py import_content_block_templates content_block_templates.json
A button is provided on the ContentBlockTemplate admin changelist page which provides a form where a JSON file can be uploaded.