Extend functionality of `django-import-export`
Project description
Description
django-import-export-extensions extends the functionality of django-import-export adding the following features:
Import/export resources in the background via Celery
Manage import/export jobs via Django Admin
DRF integration that allows to work with import/export jobs via API
Support drf-spectacular generated API schema
Additional fields and widgets (FileWidget, IntermediateM2MWidget, M2MField)
Installation
To install django-import-export-extensions, run this command in your terminal:
$ pip install django-import-export-extensions
Add import_export and import_export_extensions to INSTALLED_APPS
# settings.py
INSTALLED_APPS = (
...
"import_export",
"import_export_extensions",
)
Run migrate command to create ImportJob/ExportJob models and collectstatic to let Django collect package static files to use in the admin.
$ python manage.py migrate
$ python manage.py collectstatic
Usage
Prepare resource for your model
# apps/books/resources.py
from import_export_extensions.resources import CeleryModelResource
from .. import models
class BookResource(CeleryModelResource):
class Meta:
model = models.Book
Use CeleryImportExportMixin class and set resource_class in admin model to import/export via Django Admin
# apps/books/admin.py
from django.contrib import admin
from import_export_extensions.admin import CeleryImportExportMixin
from .. import resources
@admin.register(models.Book)
class BookAdmin(CeleryImportExportMixin, admin.ModelAdmin):
resource_class = resources.BookResource
Prepare view sets to import/export via API
# apps/books/api/views.py
from .. import resources
from import_export_extensions.api import views
class BookExportViewSet(views.ExportJobViewSet):
resource_class = resources.BookResource
class BookImportViewSet(views.ImportJobViewSet):
resource_class = resources.BookResource
Don’t forget to configure Celery if you want to run import/export in background
Links:
License:
Free software: MIT license
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
Hashes for django_import_export_extensions-0.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e319ffdbac9e4ed82db39c4b56c042c1cbca5a0d3203c958a05ad19f21ea56a |
|
MD5 | a2ece0c54b3b3b6c94663b15d467da9e |
|
BLAKE2b-256 | 75c7cb2c2c5825b64d662c3f9db5a75805b6c05ee69a986185596afa95a6b305 |
Hashes for django_import_export_extensions-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83f2966ef1c7994531f542bf9693d0dd391586e2e154463a7e037997bb569f54 |
|
MD5 | fb6a7d4041a90dbd2c1c40fdbc3f5a2c |
|
BLAKE2b-256 | 7284570c67cbaf18d03d90f6c98504f29e2c4d3102ff57f67c410e00d3c8713b |