jrief/django-admin-sortable2

DAS2 v2.x appears to assume fields are in Mutable Containers

mkoistinen opened this issue · 1 comments

def get_fields(self, *args, **kwargs):
fields = super().get_fields(*args, **kwargs)
if self.default_order_field not in fields:
fields.append(self.default_order_field)
return fields

This code here makes the assumption that the provided Iterable of fields is mutable. Tuples are not and Tuples have been the traditional container for declaring fields in Django models for a long time.

Ideally, this would do something more like:

def get_fields(self, *args, **kwargs):
    **fields = list(super().get_fields(*args, **kwargs))**
    if self.default_order_field not in fields:
        fields.append(self.default_order_field)
    return fields
jrief commented

Well spotted!
I usually do that anyway, just missed here.