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

The change in Django 3.2 to consider limit_choices_to has broken this filter. #53

Closed ndunn219 closed 3 years ago

ndunn219 commented 3 years ago

When opening the select, the choices don't show up due to this error:

'ManyToOneRel' object has no attribute 'get_limit_choices_to'
erwinfeser commented 3 years ago

+1

MDziwny commented 3 years ago

Seems linked: https://code.djangoproject.com/ticket/32619

n1k0 commented 3 years ago

Let me voice my +1 out loud :)

MDziwny commented 3 years ago

There is a workaround:

from django.db import models

class ModelA(models.Model):
    pass

class ModelB(models.Model):
    model_a = models.ForeignKey(to=ModelA, related_name="models_b")

class NonWorkingAutocompleteWithDj32(AutocompleteFilter):
    """ Autocomplete in the admin of model B """"
    title = _("Model A")
    field_name = "model_a"

class WorkingAutocompleteWithDj32(AutocompleteFilter):
    """ Autocomplete in the admin of model B """"
    title = _("Model A")
    rel_model = ModelA
    field_name = "models_b"
    parameter_name = "model_a"
ndunn219 commented 3 years ago

There is a workaround:

@MDziwny 's workaround filtered correctly for me, but it then changes the filter field to an incorrect value (i.e., not the selection that it's being filtered on).

MDziwny commented 3 years ago

it then changes the filter field to an incorrect value

Oh! You're right, I didn't notice it before, thanks :/

MDziwny commented 3 years ago

I've opened a PR with a fix, but there is no tests yet and I'm not sure I will have time to add some.