Skip to main content

Tool for django models import

Project description

๐Ÿ“ฆ Data Import for Django

PyPI version Django License: MIT

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

  • Django >= 3.0
  • djangorestframework
  • django-storages
  • polars

๐Ÿ› ๏ธ 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 oscar.core.loading import get_model
from myapp.serializers import ImportStockRecordSerializer

StockRecord = get_model("partner", "StockRecord")

class StockRecordImportJob(ImportJob):
    class Meta:
        proxy = True
        target_model = StockRecord
        serializer_class = (
            "cecotec_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

data_exchange_tool-0.1.4.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

data_exchange_tool-0.1.4-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file data_exchange_tool-0.1.4.tar.gz.

File metadata

  • Download URL: data_exchange_tool-0.1.4.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/5.15.154+

File hashes

Hashes for data_exchange_tool-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f8c1381536cc6b34d4a7d8dc4aa3aaf7ebbc230f16c95d17a53def8ace73287b
MD5 10599a06e44605d7d43e0f869014dae5
BLAKE2b-256 23d472d7dbb3934b5b01f0d969535423b412d2990e2eb9b4613fde696edb5072

See more details on using hashes here.

File details

Details for the file data_exchange_tool-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: data_exchange_tool-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 23.6 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

Hashes for data_exchange_tool-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3f9ddea7e3950d7203064f9bcacfb8422fcefe71fdb42d4fe754b7b71a58ea55
MD5 adf0bec057922e2c2619e0ebf58c9815
BLAKE2b-256 f8d1dffb6080ddb67b9e3b39d1d4385d17cc602e6a27c362f51f4ecf41ff18dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page