diff --git a/docs/_static/images/action-bands-openapi.png b/docs/_static/images/action-bands-openapi.png new file mode 100644 index 0000000..7edf6ac Binary files /dev/null and b/docs/_static/images/action-bands-openapi.png differ diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 2f8a696..b2108e3 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -172,14 +172,18 @@ the OpenAPI specification will be available. Import/Export API actions mixins + +.. figure:: _static/images/action-bands-openapi.png + + A screenshot of the generated OpenAPI specification ----------------- Alternatively you can use ``api.mixins.ExportStartActionMixin`` and ``api.mixins.ImportStartActionMixin`` to add to your current viewsets ability to create import/export jobs. -You would also need to use ``api.views.BaseExportJobViewSet/BaseExportJobForUsersViewSet`` -and ``api.views.BaseExportJobViewSet/BaseImportJobForUsersViewSet`` to setup endpoints to be able to: +You would also need to use ``api.views.BaseExportJobViewSet`` or ``BaseExportJobForUsersViewSet`` +and ``api.views.BaseImportJobViewSet`` or ``BaseImportJobForUsersViewSet`` to setup endpoints to be able to: -* ``list`` - Returns a list of jobs for the ``resource_class`` set in ViewSet -* ``retrieve`` - Returns details of a job based on the provided ID +* ``list`` - Returns a list of jobs for the ``resource_class`` set in ViewSet. +* ``retrieve`` - Returns details of a job based on the provided ID. * ``cancel`` - Stops the import/export process and sets the job's status to ``CANCELLED``. * ``confirm`` - Confirms the import after the parse stage. This action is available only in import jobs. diff --git a/docs/installation.rst b/docs/installation.rst index a816655..9149cfc 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -88,6 +88,18 @@ updated. This helps to increase the speed of import/export. The default value is 100. This parameter can be specified separately for each resource by adding ``status_update_row_count`` to its ``Meta``. +``DRF_EXPORT_DJANGO_FILTERS_BACKEND`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Specifies filter backend class for ``django-filters`` in export action. Default: +``django_filters.rest_framework.DjangoFilterBackend`` + +``DRF_EXPORT_ORDERING_BACKEND`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Specifies filter backend class for ``ordering`` in export action. Default: +``rest_framework.filters.OrderingFilter`` + Settings from django-import-export ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Additionally, the package supports settings from the original django-import-export package. diff --git a/import_export_extensions/resources.py b/import_export_extensions/resources.py index c6e5d9d..0e38990 100644 --- a/import_export_extensions/resources.py +++ b/import_export_extensions/resources.py @@ -61,9 +61,21 @@ def status_update_row_count(self): settings.STATUS_UPDATE_ROW_COUNT, ) + @classmethod + def get_model_queryset(cls) -> QuerySet: + """Return a queryset of all objects for this model. + + Override this if you + want to limit the returned queryset. + + Same as resources.ModelResource get_queryset. + + """ + return cls._meta.model.objects.all() + def get_queryset(self): """Filter export queryset via filterset class.""" - queryset = super().get_queryset() + queryset = self.get_model_queryset() try: queryset = queryset.order_by(*(self._ordering or ())) except FieldError as error: @@ -345,17 +357,5 @@ class CeleryResource(CeleryResourceMixin, resources.Resource): class CeleryModelResource(CeleryResourceMixin, resources.ModelResource): """ModelResource which supports importing via celery.""" - @classmethod - def get_model_queryset(cls) -> QuerySet: - """Return a queryset of all objects for this model. - - Override this if you - want to limit the returned queryset. - - Same as resources.ModelResource get_queryset. - - """ - return cls._meta.model.objects.all() - class Meta: store_instance = True diff --git a/test_project/fake_app/resources.py b/test_project/fake_app/resources.py index bbf9e7d..384d94d 100644 --- a/test_project/fake_app/resources.py +++ b/test_project/fake_app/resources.py @@ -44,9 +44,13 @@ class Meta: def get_queryset(self): """Return a queryset.""" - return Artist.objects.all().prefetch_related( - "membership_set__band", - "bands", + return ( + super() + .get_queryset() + .prefetch_related( + "membership_set__band", + "bands", + ) ) @@ -71,7 +75,11 @@ class Meta: def get_queryset(self): """Return a queryset.""" - return Band.objects.all().prefetch_related( - "membership_set__artist", - "artists", + return ( + super() + .get_queryset() + .prefetch_related( + "membership_set__artist", + "artists", + ) )