Skip to content
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

How to use ImportExportModelAdmin together with SortableAdminMixin from admin-sortable2 #1531

Closed
micudaj opened this issue Jan 28, 2023 · 13 comments
Labels

Comments

@micudaj
Copy link

micudaj commented Jan 28, 2023

I tried to use ImportExportModelAdmin together with SortableAdminMixin from admin-sortable2, but I get the following error. Any idea how and if. these can work together?

join() argument must be str, bytes, or os.PathLike object, not 'list'
Request Method:	GET
Request URL:	http://xxxxx.de/admin/tenant_only/frage/
Django Version:	4.1.5
Exception Type:	TypeError
Exception Value:	
join() argument must be str, bytes, or os.PathLike object, not 'list'
Exception Location:	/usr/local/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/genericpath.py, line 152, in _check_arg_types
Raised during:	adminsortable2.admin.changelist_view

Thanks you in advance!

@matthewhegarty
Copy link
Contributor

At first glance it looks like an error in adminsortable2, but can you post the full stack trace (along with the versions you are using)

@matthewhegarty
Copy link
Contributor

Did you solve this? Can we close?

@micudaj
Copy link
Author

micudaj commented Feb 8, 2023

sorry for not answering. In the stacktracke the error appears in a class of adminsortable2, so I opened an issue there. So I guess we can close here for now, unless you have an idea?

@matthewhegarty
Copy link
Contributor

matthewhegarty commented Feb 8, 2023

Link

Will close for now and will re-open if it looks like an import-export issue.

@PetrDlouhy
Copy link
Contributor

I think this is django-import-export issue.
I was able to make the sorting work together with import/export buttons by following code:

class MyAdmin(ImportExportMixin, SortableAdminMixin, admin.ModelAdmin):                                                                                                        
     change_list_template = "admin/import_export/change_list.html"

The substantial part is the change_list_template which I think should be set explicitly in django-import-export and shouldn't be needed in the users code.

For the reverse order of the mixins ((SortableAdminMixin, ImportExportMixin, admin.ModelAdmin)) which should in theory also work I think is at fault the django-adminsortable2 which defines list as change_list_template.

@matthewhegarty
Copy link
Contributor

matthewhegarty commented Sep 14, 2023

We decided to document these clashes rather than try to fix. If we have a robust fix in future, we can perhaps consider including it.

@micudaj
Copy link
Author

micudaj commented Sep 15, 2023

I think this is django-import-export issue. I was able to make the sorting work together with import/export buttons by following code:

class MyAdmin(ImportExportMixin, SortableAdminMixin, admin.ModelAdmin):                                                                                                        
     change_list_template = "admin/import_export/change_list.html"

The substantial part is the change_list_template which I think should be set explicitly in django-import-export and shouldn't be needed in the users code.

For the reverse order of the mixins ((SortableAdminMixin, ImportExportMixin, admin.ModelAdmin)) which should in theory also work I think is at fault the django-adminsortable2 which defines list as change_list_template.

I changed my code to this. I can now see the drag handler, but cannot use them as they don't work. Am I anything missing. Works when I only use the SortableAdminMixin.

@matthewhegarty
Copy link
Contributor

You could try @PetrDlouhy patch and see if that works for you. I decided not to merge into the main codebase, instead documented the workaround here.

@micudaj
Copy link
Author

micudaj commented Sep 15, 2023

Unfortunately this also didn't work. Still drag & drop is not working in combination with import/export mixin

@matthewhegarty
Copy link
Contributor

Sorry to say I can't help further. It looks like various 3rd party libraries don't work well together. If you get it working or find a workaround, please post back here.

@PetrDlouhy
Copy link
Contributor

@matthewhegarty I think that ideal state of this issue is, that cooperation with admin-sortable2 works out of the box without any workarounds (maybe even independently on order of the mixins).
Although it would be difficult to determine which library is at fault or if there are changes need to be implemented in Django itself to make sorting out template overriding easier with mixins.

I would like to contribute to solve this issue somehow.

@micudaj I have identified another issue which causes that admin_sortable2_config is not set and the drag&drop doesn't work. The cause is clash of variable of the same name in both libraries: #1633
There is still needed to apply workaround after this change. The sorting drag&drop should work with following code:

class MyAdmin(ImportExportMixin, SortableAdminMixin, admin.ModelAdmin):
    change_list_template = "adminsortable2/change_list.html"

@micudaj
Copy link
Author

micudaj commented Sep 18, 2023

@matthewhegarty I think that ideal state of this issue is, that cooperation with admin-sortable2 works out of the box without any workarounds (maybe even independently on order of the mixins). Although it would be difficult to determine which library is at fault or if there are changes need to be implemented in Django itself to make sorting out template overriding easier with mixins.

I would like to contribute to solve this issue somehow.

@micudaj I have identified another issue which causes that admin_sortable2_config is not set and the drag&drop doesn't work. The cause is clash of variable of the same name in both libraries: #1633 There is still needed to apply workaround after this change. The sorting drag&drop should work with following code:

class MyAdmin(ImportExportMixin, SortableAdminMixin, admin.ModelAdmin):
    change_list_template = "adminsortable2/change_list.html"

Hey PetrDlouhy,

With your fixes drag & drop works. Thank you! But now I have the import export buttons in the top right twice. It is more of a cosmetic topic, but maybe this can easily be avoided.

@micudaj
Copy link
Author

micudaj commented Sep 18, 2023

Never mind. Was an issue on my side with a change I tried before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants