Skip to main content

Import and export

Added in 1.0.1

Attach ImportOption and/or ExportOption to a ModelAdmin. Chassis adds list-page buttons (in the changelist toolbar), preview/confirm for import, and history records.

Full field tables: Options catalog.

Page anatomy

Import

  1. Toolbar button → import landing (upload form + backend picker).
  2. Preview page: accepted rows, skipped duplicates, validation errors (ImportPreviewDTO family).
  3. Confirm apply → ImportApplyService writes rows atomically.
  4. History page: ImportHistory rows, download of the source file.

Export

  1. Toolbar button → export form (format, backend, optional filter_fields).
  2. Job writes a file to STORAGES['media'] and stores ExportHistory.
  3. History page: status, backend, download of the finished file.

Both flows share the backend picker documented in Import and export backends.

from django_chassis.enums import ExportFormat, ImportFormat
from django_chassis.options import ExportOption, ImportOption


class BookAdmin(ChassisAdminMixin, ModelAdmin):
options = [
ImportOption(permission='import_book', fields=['title', 'isbn'], formats=[ImportFormat.JSON, ImportFormat.XML]),
ExportOption(
permission='export_book',
fields=['title', 'isbn', 'status'],
formats=[ExportFormat.JSON, ExportFormat.CSV, ExportFormat.XLSX],
filter_fields=['status'],
include_journals=False,
),
]

permission is required and cannot be blank. Empty formats or filter_fields lists raise ValueError at construction.

Formats

FlowFormats
ImportJSON, XML
ExportJSON, XML, CSV, XLSX

formats=None means every format in the enum.

Import flow

  1. Upload a file on the import landing page.
  2. Chassis builds a preview: accepted rows, skipped duplicates, validation errors.
  3. Confirm apply. ImportApplyService creates rows atomically.
  4. Uniqueness-based duplicates are skipped, not overwritten.

Preview DTOs: ImportPreviewDTO, ImportPreviewRowDTO, ImportPreviewSkippedRowDTO.

Export flow

Export writes a file and stores it on ExportHistory. Optional filter_fields become form filters. include_journals=True adds model history/journal data when the project provides it.

Storage

Files go to STORAGES['media']. Configure that storage before enabling import/export in production.

History

ImportHistory and ExportHistory persist job status, backend, and file references. Users download finished export files from the history page. Both tables are created by the package's single initial migration (django_chassis.0001_initial). Run migrate after installing the app.

Changed in 1.0.1

Their database names are chassis_import_histories and chassis_export_histories.

See also