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

Sorting subsets of objects broken for Django 4.2? #263

Open
eastface opened this issue Jul 26, 2023 · 1 comment
Open

Sorting subsets of objects broken for Django 4.2? #263

eastface opened this issue Jul 26, 2023 · 1 comment

Comments

@eastface
Copy link

I am using a sorting_filters tuple to filter subsets of objects. This was working fine previously, and I suspect it stopped working when I upgraded to Django 4 (though I haven't fully checked that).

The error I see is

Cannot resolve keyword 'sort_filter' into field.

And debug shows

filters {'sort_filter': '0'}
request <WSGIRequest: GET '/admin/gallery/slide/?sort_filter=0'>

at line 60 in changelist_view of django-admin-sortable/adminsortable/admin.py.

It looks to me like the sort_filter in the querystring should not be parsed into filters. This is done in the get_querystring_filters method which already ignores keys IGNORED_PARAMS and PAGE_VAR. By also ignoring sort_filter and e (which can also get in there). My code is working again.

I hope this is useful and allows someone to spot the correct quick fix.

@eastface
Copy link
Author

And just in case anyone needs a quick workaround, for me it works to override get_querystring_filters in my admin class:

class SlideAdmin(SortableAdmin):
    list_display = ('headline', 'strapline', 'link', )

    def get_querystring_filters(self, request):
        filters = super().get_querystring_filters(request)
        return {k: v for k, v in filters.items() if k != 'sort_filter' and k != 'e'}

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

No branches or pull requests

1 participant