0

I want to use django-admin-sortable2 django-import-export package together in admin panel. Here is the code:

class University(models.Model):
    name = models.CharField(max_length=50, help_text="University or Institution Name")
    short_name = models.CharField(blank=True, max_length=10, help_text="University or Institution 
 Short Name")
    order = models.PositiveIntegerField(
        default=0,
        blank=False,
        null=False,
    )
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f'{self.id}-{self.name}' 

    class Meta:
        ordering = ['order'] 

admin.py:

from import_export import resources
from import_export.admin import ImportExportModelAdmin

from adminsortable2.admin import SortableAdminMixin
# Register your models here.

class UniversityResource(resources.ModelResource):
    class Meta:
        model = University
        exclude = ('created_at', 'updated_at',)


class UniveresityAdmin(ImportExportModelAdmin, SortableAdminMixin, admin.ModelAdmin):
    resource_classes = [UniversityResource]

admin.site.register(University, UniveresityAdmin)
  

But this is not working, If I use:

class UniveresityAdmin(ImportExportModelAdmin, SortableAdminMixin, admin.ModelAdmin):
    resource_classes = [UniversityResource]

Console:

failed to assign change_list_template attribute (see issue 1521)

This is the output:
enter image description here

If I use:

class UniveresityAdmin(ImportExportModelAdmin, SortableAdminMixin,):

This provides: enter image description here And if I use:

class UniveresityAdmin(SortableAdminMixin, ImportExportModelAdmin,):

This provides:

TypeError at /admin/core/university/
join() argument must be str, bytes, or os.PathLike object, not 'list'

Both works single handed if I remove either one of them. But I want to use both package together. Is there any workaround to solve this issue? Thanks in advance.

3
  • can you expand on what is not working? Are you seeing any errors? See this thread Commented Jun 14, 2023 at 13:00
  • If I use class UniveresityAdmin( SortableAdminMixin, ImportExportModelAdmin,) then it occurs TypeError: join() argument must be str, bytes, or os.PathLike object, not 'list' errror. And If I use UniveresityAdmin(ImportExportModelAdmin, SortableAdminMixin): then drag and drop option is not visible. Drag and drop and import-export both not visible by using UniveresityAdmin(ImportExportModelAdmin, SortableAdminMixin, admin.ModelAdmin). by this combination. Commented Jun 14, 2023 at 14:35
  • I have added the errors and result. Please check it. Commented Jun 14, 2023 at 14:57

2 Answers 2

2

The short answer is that import-export and admin-sortable2 don't work together. AFAIK there is no workaround.

The reason is that admin-sortable2 defines change_list_template as a property meaning it cannot be reset. In import-export, all we can do is detect this and log the error:

failed to assign change_list_template attribute (see issue 1521)

The link to this issue is here. There is an open issue on admin-sortable2.

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

class SomeAdmin(SortableAdminMixin,ImportExportMixin , admin.ModelAdmin):

should work..

P.S Do not forget to import ImportExportMixin:

from import_export.admin import ImportExportModelAdmin, ImportExportMixin, 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.