jrief/django-admin-sortable2

Add support for django-unfold

Opened this issue · 2 comments

First and foremost, I would like to extend my gratitude for developing such an impressive function.

I am writing to report a compatibility issue I encountered with the django-unfold when integrated with the sortable2 interface. It seems that the styles and action buttons from Sortable2 do not align well with the Unfold design.

image

Could you please consider enhancing the compatibility between these tools in your future updates? Any assistance or guidance in this matter would be greatly appreciated.

Thank you for your attention to this matter. Looking forward to your favorable response.

Best regards,
Froggen

Feel free to create a pull request. I currently have no need for django-unfold but I'm open for enhancements to this library.

@twFroggen Encountered this same issue, looks like a few people out there have. I managed to solve this issue by extending the SortableAdminMixin class and patching in a modified version of the MovePageActionForm class.

Original MovePageActionForm

class MovePageActionForm(admin.helpers.ActionForm):
    step = IntegerField(
        required=False,
        initial=1,
        widget=widgets.NumberInput(attrs={'id': 'changelist-form-step'}),
        label=False
    )
    page = IntegerField(
        required=False,
        widget=widgets.NumberInput(attrs={'id': 'changelist-form-page'}),
        label=False
    )

MovePageActionForm Patched with Unfold Classes

# from unfold.forms import ActionForm
class UnfoldMovePageActionForm(ActionForm):
    step = IntegerField(
        required=False,
        initial=1,
        # from unfold.widgets import UnfoldAdminIntegerFieldWidget
        widget=UnfoldAdminIntegerFieldWidget(attrs={'id': 'changelist-form-step'}),
        label=False
    )
    page = IntegerField(
        required=False,
        widget=UnfoldAdminIntegerFieldWidget(attrs={'id': 'changelist-form-page'}),
        label=False
    )
    
# Replace action_form in extended class
class UnfoldSortableMixin(SortableAdminMixin):
    action_form = UnfoldMovePageActionForm

# Use it in your model admin
@admin.register(MyModel)
class MyModelAdmin(UnfoldSortableMixin, ModelAdmin):
    # ... stuff here ...