-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it working in multiple admin sites context #59
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like Please, add definition or import of |
||||||
# ... | ||||||
cutom_admin_site.register(ExportJob, ExportJobAdmin) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Don't forget to `configure Celery <https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html>`_ | ||||||
if you want to run import/export in background | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,13 @@ class ExportJobAdmin( | |
"cancel_jobs", | ||
) | ||
|
||
def get_form(self, request: WSGIRequest, obj=None, **kwargs): | ||
"""Push admin site to form.""" | ||
form = super().get_form(request, obj, **kwargs) | ||
|
||
form.admin_site = self.admin_site | ||
return form | ||
Comment on lines
+45
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it really required? Why? Please try to answer questions We also made some changes to the admin mixins, so this logic can probably be put into |
||
|
||
def export_data_action( | ||
self, | ||
request: WSGIRequest, | ||
|
@@ -67,7 +74,7 @@ def get_urls(self): | |
urls = super().get_urls() | ||
export_urls = [ | ||
re_path( | ||
route=r"^(?P<job_id>\d+)/progress/$", | ||
route=r"^celery-export/(?P<job_id>\d+)/progress/$", | ||
view=self.admin_site.admin_view(self.export_job_progress_view), | ||
name="export_job_progress", | ||
), | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -43,6 +43,13 @@ class ImportJobAdmin( | |||||
"confirm_jobs", | ||||||
) | ||||||
|
||||||
def get_form(self, request: WSGIRequest, obj=None, **kwargs): | ||||||
"""Push admin site to form.""" | ||||||
form = super().get_form(request, obj, **kwargs) | ||||||
|
||||||
form.admin_site = self.admin_site | ||||||
return form | ||||||
|
||||||
def get_queryset(self, request: WSGIRequest): | ||||||
"""Override `get_queryset`. | ||||||
|
||||||
|
@@ -61,9 +68,9 @@ def get_urls(self): | |||||
urls = super().get_urls() | ||||||
import_urls = [ | ||||||
re_path( | ||||||
r"^(?P<job_id>\d+)/progress/$", | ||||||
r"^celery-import/(?P<job_id>\d+)/progress/$", | ||||||
self.admin_site.admin_view(self.import_job_progress_view), | ||||||
name="import_job_progress", | ||||||
name= "import_job_progress", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
), | ||||||
] | ||||||
return import_urls + urls | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's provide a link to the Django Documentation about multiple/custom admin site (https://docs.djangoproject.com/en/stable/ref/contrib/admin/#customizing-the-adminsite-class)