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 75 forks source link

Intent question #54

Open jaredahern opened 3 years ago

jaredahern commented 3 years ago

I'm doing a significant revamp to this filter, which will include things like more easily overridden widgets and fields, as well as support for multiple select. In the process of doing this, I ran into a point of confusion regarding our class variables - partially caused by my prior incorporated revisions. Basically, what do people expect field_name and parameter_name to do in the case of relations that span multiple models?

Example: you want to single-filter a Book model by publisher__country, where Book.publisher is a FK to Publisher.pk and Publisher.country is a FK to Country.pk.

As far as I can tell, this is the current situation:

But I think this is a bit sub-optimal, and confusing. Overwriting the class-level parameter_name is confusing and a bit contrary to how SimpleListFilter works, which complicates the factory version; parameter_name is dual-used and doesn't allow custom non-lookup GET parameters; and while we only have README docs for field_name, it doesn't actually handle the nested relations, leading to user confusion.

I propose that the filter should work as follows:

Alternatively, we could use something other than field_name as the main variable, clearly indicating that its old use is depreciated. Since we don't really even document how to handle nested relations now (I'll address that as well), I'm not too worried about breakage in a pre-1.0 version, but we can handle that however seems best.

What say you all?

farhan0581 commented 3 years ago

what about the name of the field name in the html widget that appears in the panel ? will field_name do the job ? Also I am also fine to merge the fields and use only one of them if possible. The idea is to keep this as simple as possible while defining the filter class.

jaredahern commented 3 years ago

what about the name of the field name in the html widget that appears in the panel ?

Good point. Right now it is controlled via the title class attribute. Should that default to field_name if no separate title is provided?

Also I am also fine to merge the fields and use only one of them if possible. The idea is to keep this as simple as possible while defining the filter class.

Great, thanks for the feedback! I'll put together a PR for you to review.

ndunn219 commented 3 years ago

@jaredahern, are you testing this against Django 3.2? If so, please keep in mind issue #53 as well.

jaredahern commented 3 years ago

Sure, I can test there too, @ndunn219 . I'm mostly done with my fixes, but I have one last bug that I'm trying to sort out before I create a PR. I haven't looked at it in great detail, but hopefully support for Django 3.2 won't be too complex of a change.