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.4.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76f24c1741c8265a4e473a18903db222afc5a88213a467b218d46a041e2fd6c6 |
|
MD5 | 01695c4b758bcf3c9fddfc0f1b0ed0b6 |
|
BLAKE2b-256 | fd970a14944554df336a0091a32f6a4e33e403a0354805dc4b9273f1fbe4bdae |
Hashes for django_import_export_extensions-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f46b81d738c33f0fcd631aa7dba2ba473b525e35b00a3474ee8447d4030a0fa |
|
MD5 | a30c5758aadf58447b35c6fa53a7f568 |
|
BLAKE2b-256 | b23ddc7be1da80ca22789bda21c2b622b0c03c000c6be3125d7a07ea7b8663a0 |