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

How to create filter by value of unrelated model? #48

Open SuperMasterBlasterLaser opened 3 years ago

SuperMasterBlasterLaser commented 3 years ago

Hello.

First of all, I want to thank all contributors for this lib. I have some case in my project.

Lets say that I have these models:

class Company(model.Model):
    identifier = model.CharField(unique=True, max_length=25)

class Item(model.Model):
     supplier_identifier = model.CharField(max_length=25)

The models Company and Item are not related by any foreign key. Lets just say that I have reasons for that. I want to filter Item models by its supplier_identifier field and autocomplete values should be provided from Company model's identifier field.

I know that I should prepare special View for searching. However I don't know how to force filter to get value of specific field.

daniestrella1 commented 3 years ago

+1