farhan0581 / django-admin-autocomplete-filter

A simple Django app to render list filters in django admin using autocomplete widget.
GNU General Public License v3.0
351 stars 76 forks source link

DisallowedModelAdminLookup with Django 5 #92

Open Vayel opened 9 months ago

Vayel commented 9 months ago

Hi!

I have the following models:

class Author(models.Model):
    pass

class Book(models.Model):
    author = models.ForeignKey(Author, on_delete=models.CASCADE)

And the following admin site:

class AuthorFilter(AutocompleteFilter):
    title = _("author")
    field_name = "author"

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    list_filter = (AuthorFilter,)

It's displayed fine but when I run the filter I get the following error:

DisallowedModelAdminLookup at /_admin/app/book/
Filtering by author__pk__exact not allowed

Actually, it seems to be a regression in Django 5.0.1: https://github.com/django/django/commit/8db593de05c3516c939b7d4b9eb91e8791f4c79a

It was fixed in Django 5.0.2 but the filter seems to work with use_pk_exact = False only:

class AuthorFilter(AutocompleteFilter):
    title = _("author")
    field_name = "author"
    use_pk_exact = False
arthur-verta commented 9 months ago

Hello, Same problem for me. Even on Django 5.0.2, and setting use_pk_exact = False, i end up with the same DisallowedModelAdminLookup error.