Import and export
Add the two options to a ModelAdmin and declare their distinct codenames in model permissions or the Chassis permission registry.
from django.contrib.admin import ModelAdmin
from django_chassis.mixins import ChassisAdminMixin
from django_chassis.enums import ExportFormat, ImportFormat
from django_chassis.options import ExportOption, ImportOption
class BookAdmin(ChassisAdminMixin, ModelAdmin):
options = [
ImportOption(
view_permission='view_book_import', upload_permission='upload_book_import',
fields=['title', 'isbn'], formats=[ImportFormat.JSON, ImportFormat.XML]
),
ExportOption(
view_permission='view_book_export', create_permission='create_book_export',
download_permission='download_book_export', fields=['title', 'isbn', 'status'],
formats=[ExportFormat.JSON, ExportFormat.CSV, ExportFormat.XLSX],
filter_fields=['status'], include_journals=False
)
]
Upgrade from 1.0.22
Use the complete guide to upgrading from 1.0.22 for schema changes, access grants and legacy records.
Run migrations. Replace each legacy permission with the named permissions shown above and grant them to the appropriate groups. Old positional option arguments still load. Prior grants alone leave both buttons hidden. Chassis checks report missing operation permissions (E005), operation codes reused across actions or mounted admin sections (E006), and undeclared codes (E003).
Both flows require the model view right and their own view permission. Each section lists the latest 50 operations across all authors for that flow. Upload permits validation and launch. Create permits export launch. Download permits retrieving a completed export. Histories belong to a model and admin site. A pre-upgrade row with an empty section resolves only if exactly one eligible ModelAdmin on a mounted site offers that flow. Without a unique match, the interfaces hide the old row and its file. Version 1.0.22 stored the concrete model type even for proxy sections. The owner check therefore includes every base or proxy registration sharing that concrete model and flow. To assign an ambiguous row, set both its section to the verified site name and its content_type to ContentType.objects.get_for_model(owner_model, for_concrete_model=False) in one update before processing queued records or granting access to history. Queued jobs apply the owner's current field, format and journal restrictions. Old PREVIEW rows remain stored.
Import
Choose JSON or XML, the backend and selected fields. Match the filename extension to the chosen format. JSON accepts a UTF-8 array of objects or an object with an objects array. XML accepts <objects> or <export><objects>…</objects></export>, with one <object> per row. The optional file check shows source columns, matching target names, new rows, duplicates and row errors on the same form. Column mapping maps selected model fields to input columns. Leave it empty for matching names. Include every model field required for creation in the import allowlist.
File inspection creates no history record. A successful submission opens the operation status page. For custom forms, retain the same operation_id when retrying an accepted submission. Existing unique keys and duplicates within the file are skipped. An invalid row prevents import of the batch. The source file stays in STORAGES['media'] for processing. Keep the storage private.
Export
The form offers JSON, XML, CSV and XLSX, subject to the option's formats. The current changelist and configured filters determine the accepted object IDs. Optional journal rows contain selected fields and available history ID, date and type. XLSX stores strings as literal text. CSV prefixes formula-like cells with an apostrophe.
Operation details use the standard read-only Admin fieldset with a separate action bar. Status pages show queued, processing, successful or failed operations and available counts. The download action serves completed exports. Python queue and project-worker jobs are published after commit. Backend configuration
In 1.0.23, XLSX serialization can fail if a selected column yields a raw UUID, for example a foreign key with a UUID primary key. Deselect the UUID column for XLSX or use CSV or JSON when the identifier must be included. The transfer walkthrough shows the XLSX path.
Formatting cells for streamed reports
Added in 1.0.24django_chassis.services.ImportExportSerializationService applies the bulk export rules to individual
cells. For every header and data row on each sheet, call xlsx_cell_value(value=value, sheet=sheet)
before appending the row to a regular or write-only openpyxl worksheet. For each CSV header or data
cell, pass csv_cell_text(value=value) to the CSV writer. XLSX preserves literal text in strings and
keeps numeric cells typed. CSV adds the apostrophe only to strings covered by the existing protection.
Translation catalog
Choose one existing language, including an inactive one. The JSON file is a flat object mapping translation keys to exact text. New keys initialize every language. Existing keys update the selected language and omitted keys keep their values. The operation stores the language code.