diff --git a/README.rst b/README.rst index 9109f1b..fbbdf88 100644 --- a/README.rst +++ b/README.rst @@ -121,6 +121,24 @@ Prepare view sets to import/export via API resource_class = resources.BookResource +If you use multiple or custom admin site, register required models to them + +.. code-block:: python + + # app/admin.py + from import_export_extensions.models import ExportJob + from import_export_extensions.admin.model_admins.export_job_admin import ExportJobAdmin + + from django.apps import AppConfig + + custom_admin_site = BaseAdminSite(name="custom_admin") + # ... + cutom_admin_site.register(ExportJob, ExportJobAdmin) + + + + + Don't forget to `configure Celery `_ if you want to run import/export in background diff --git a/import_export_extensions/admin/forms/export_job_admin_form.py b/import_export_extensions/admin/forms/export_job_admin_form.py index 9679323..90b9552 100644 --- a/import_export_extensions/admin/forms/export_job_admin_form.py +++ b/import_export_extensions/admin/forms/export_job_admin_form.py @@ -27,7 +27,7 @@ def __init__( ): """Provide `export_progressbar` widget the `ExportJob` instance.""" super().__init__(*args, instance=instance, **kwargs) - url_name = "admin:export_job_progress" + url_name = f"{self.admin_site.name}:export_job_progress" self.fields["export_progressbar"].widget = ProgressBarWidget( job=instance, url=reverse(url_name, args=(instance.id,)), diff --git a/import_export_extensions/admin/forms/import_job_admin_form.py b/import_export_extensions/admin/forms/import_job_admin_form.py index efd2b04..0ab79c8 100644 --- a/import_export_extensions/admin/forms/import_job_admin_form.py +++ b/import_export_extensions/admin/forms/import_job_admin_form.py @@ -26,7 +26,7 @@ def __init__( ): """Provide `import_progressbar` widget the ``ImportJob`` instance.""" super().__init__(*args, instance=instance, **kwargs) - url_name = "admin:import_job_progress" + url_name = f"{self.admin_site.name}:import_job_progress" self.fields["import_progressbar"].label = ( "Import progress" if instance.import_status == models.ImportJob.ImportStatus.IMPORTING diff --git a/import_export_extensions/admin/mixins/export_mixin.py b/import_export_extensions/admin/mixins/export_mixin.py index 27b084e..896e988 100644 --- a/import_export_extensions/admin/mixins/export_mixin.py +++ b/import_export_extensions/admin/mixins/export_mixin.py @@ -197,7 +197,7 @@ def export_job_status_view( ) context = self.get_context_data(request) - job_url = reverse("admin:export_job_progress", args=(job.id,)) + job_url = reverse(f"{self.admin_site.name}:export_job_progress", args=(job.id,)) context["title"] = _("Export status") context["opts"] = self.model_info.meta @@ -289,7 +289,7 @@ def _redirect_to_export_status_page( ) -> HttpResponse: """Shortcut for redirecting to job's status page.""" url_name = ( - f"admin:{self.model_info.app_model_name}_export_job_status" + f"{self.admin_site.name}:{self.model_info.app_model_name}_export_job_status" ) url = reverse(url_name, kwargs=dict(job_id=job.id)) query = request.GET.urlencode() @@ -304,7 +304,7 @@ def _redirect_to_export_results_page( ) -> HttpResponse: """Shortcut for redirecting to job's results page.""" url_name = ( - f"admin:{self.model_info.app_model_name}_export_job_results" + f"{self.admin_site.name}:{self.model_info.app_model_name}_export_job_results" ) url = reverse(url_name, kwargs=dict(job_id=job.id)) query = request.GET.urlencode() diff --git a/import_export_extensions/admin/mixins/import_mixin.py b/import_export_extensions/admin/mixins/import_mixin.py index 3c6a54f..f2a34b2 100644 --- a/import_export_extensions/admin/mixins/import_mixin.py +++ b/import_export_extensions/admin/mixins/import_mixin.py @@ -239,7 +239,7 @@ def celery_import_job_status_view( ) context = self.get_context_data(request) - job_url = reverse("admin:import_job_progress", args=(job.id,)) + job_url = reverse(f"{self.admin_site.name}:import_job_progress", args=(job.id,)) context.update( dict( title=_("Import status"), @@ -362,7 +362,7 @@ def _redirect_to_import_status_page( ) -> HttpResponseRedirect: """Shortcut for redirecting to job's status page.""" url_name = ( - f"admin:{self.model_info.app_model_name}_import_job_status" + f"{self.admin_site.name}:{self.model_info.app_model_name}_import_job_status" ) url = reverse(url_name, kwargs=dict(job_id=job.id)) query = request.GET.urlencode() @@ -376,7 +376,7 @@ def _redirect_to_results_page( ) -> HttpResponseRedirect: """Shortcut for redirecting to job's results page.""" url_name = ( - f"admin:{self.model_info.app_model_name}_import_job_results" + f"{self.admin_site.name}:{self.model_info.app_model_name}_import_job_results" ) url = reverse(url_name, kwargs=dict(job_id=job.id)) query = request.GET.urlencode() diff --git a/import_export_extensions/admin/model_admins/export_job_admin.py b/import_export_extensions/admin/model_admins/export_job_admin.py index 3efb78f..9b5b529 100644 --- a/import_export_extensions/admin/model_admins/export_job_admin.py +++ b/import_export_extensions/admin/model_admins/export_job_admin.py @@ -67,7 +67,7 @@ def get_urls(self): urls = super().get_urls() export_urls = [ re_path( - route=r"^(?P\d+)/progress/$", + route=r"^celery-export/(?P\d+)/progress/$", view=self.admin_site.admin_view(self.export_job_progress_view), name="export_job_progress", ), diff --git a/import_export_extensions/admin/model_admins/import_job_admin.py b/import_export_extensions/admin/model_admins/import_job_admin.py index d524cb4..a09149e 100644 --- a/import_export_extensions/admin/model_admins/import_job_admin.py +++ b/import_export_extensions/admin/model_admins/import_job_admin.py @@ -61,9 +61,9 @@ def get_urls(self): urls = super().get_urls() import_urls = [ re_path( - r"^(?P\d+)/progress/$", + r"^celery-import/(?P\d+)/progress/$", self.admin_site.admin_view(self.import_job_progress_view), - name="import_job_progress", + name= "import_job_progress", ), ] return import_urls + urls