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.0a0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbb1a5ad19ee6c0d2f4781b6bafc8918427d635511f9a612f73f01780f7319a3 |
|
MD5 | a6db64c114fbf9aece65b4330d2057f0 |
|
BLAKE2b-256 | a801abc55e29b3f15f6eb1c8cd10bd049c9fce39ea1647262647d6f18066f6bd |
Hashes for django_import_export_extensions-0.4.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5f0939f3419517a5e5e216ced844e929e65c6992241562e2392d9ceb3eded1e |
|
MD5 | 18c145f2ce2c4a618f10df6993ec1e39 |
|
BLAKE2b-256 | 30034bc34de3e9b60e0e44135c2088ab6afbf67ecbc354770cd28c463a4e7fb2 |