Tool for django models import
Project description
๐ฆ Data Import for Django
This package provides a reusable Django library for managing data import processes with features such as:
- Data preview before final import.
- Row-level error validation.
- Background processing with Celery.
- Import restrictions based on job state.
- Support for multiple content types.
- Integration with S3 or any storage backend via
django-storages.
๐ Installation
pip install django-data-exchange-tool
Dependencies
- Python: 3.11
- Django: >= 3.0
- Celery: >= 5.0
- Redis (broker/result backend)
- S3 vรญa django-storages + boto3
๐ ๏ธ Usage
1๏ธโฃ Django settings
This package supports uploading and storing import files on Amazon S3 using django-storages.
To enable this feature, define the following settings in your settings.py:
# Required: S3 bucket name used for storing import files
MODEL_DATA_EXCHANGE_S3_BUCKET_NAME = "my-import-bucket"
# Optional: Base path (prefix) within the bucket
# Example: If set to "imports", files will be stored in "imports/<subfolder>/<file>"
MODEL_DATA_EXCHANGE_S3_BASE_PATH = "imports"
# Optional: Specify other celery queues for Preview task and Import task.
# Value `data_exchange_shared_queue` by default
DATA_EXCHANGE_PREVIEW_QUEUE = "preview_queue"
DATA_EXCHANGE_IMPORT_QUEUE = "import_queue"
2๏ธโฃ Create an Import Job
All import operations are managed entirely via the Django Admin interface:
- Navigate to the Import Jobs section in Django Admin.
- Upload your data file (CSV, XLSX, etc.).
- Select the target content type you want to import.
3๏ธโฃ Preview Data
- After saving, the system automatically generates a data preview.
- This allows you to check for validation errors before proceeding.
4๏ธโฃ Confirm Import
- In the job detail view, click Confirm Import.
- The system ensures:
- No other job of the same content type is currently in progress.
- The current job state is allowed for confirmation.
- There are no preview errors blocking the process.
๐ Extending the Library
This package is designed to be extendable.
To create a custom importer for a specific model:
1๏ธโฃ Create a proxy model
from data_exchange_tool.models import ImportJob
from models import StockRecord
from myapp.serializers import ImportStockRecordSerializer
class StockRecordImportJob(ImportJob):
class Meta:
proxy = True
target_model = StockRecord
serializer_class = (
"my_apps.data_exchange_tool.partner.serializers.ImportStockRecordSerializer"
)
2๏ธโฃ Create a custom admin
from data_exchange_tool.admin import GenericImporterModelAdmin
class StockRecordNewImporterAdmin(GenericImporterModelAdmin):
...
This allows you to:
- Define custom serializers for validating and transforming data.
- Use proxy models to target specific Django models.
- Leverage the built-in admin UI for job management.
๐ Import Job Flow Diagram
โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ CREATED โ โโโโโโถ โ PREVIEW_SUCCEEDED โ โโโโโโถ โ IMPORT_IN_PROGRESS โ โโโโโโถ โ IMPORT_SUCCEEDED โ
โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ PREVIEW_FAILED โ โ PREVIEW_FAILED โ โ IMPORT_FAILED โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
Project details
Release history Release notifications | RSS feed
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 data_exchange_tool-0.1.7.tar.gz.
File metadata
- Download URL: data_exchange_tool-0.1.7.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4415413d8cada8adcbbe160309a75accc828978b57bb752a1c7d50944566bc12
|
|
| MD5 |
4ccb662ef6b560e637892dd9e48bbd25
|
|
| BLAKE2b-256 |
97914ea482c893604648a3061f3bb4e294362d57f8bef42c5b5cba96e1ed12af
|
File details
Details for the file data_exchange_tool-0.1.7-py3-none-any.whl.
File metadata
- Download URL: data_exchange_tool-0.1.7-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16680c5e5425203d46dce31ee6f0dbd3b3984e2d0c79620c53e673e1527660eb
|
|
| MD5 |
7e501e08b6aa2b6c5207d3448ff132c9
|
|
| BLAKE2b-256 |
6b3717a0e2000fcc65c556c1c77bfe8f9e31a2e1d6646b3465c7aad631d3e306
|