Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSuperiorStanislav committed Jan 20, 2025
1 parent c239876 commit 406b222
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
Binary file added docs/_static/images/action-bands-openapi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
12 changes: 12 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 13 additions & 13 deletions import_export_extensions/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
20 changes: 14 additions & 6 deletions test_project/fake_app/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)


Expand All @@ -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",
)
)

0 comments on commit 406b222

Please sign in to comment.