iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
718 stars 47 forks source link

Filter on FK not working when freetext_search "pre-defined" in Style or in "base" Table #404

Open berycz opened 1 year ago

berycz commented 1 year ago

this bug is somehow related to #400 - got fixed by it, but the question is why? :)

I'm adding this as a new issue after discussion with boxed on discord, because it might need furter investigation, or another test for that or something.

In the scenario with models Artist and Album I have

class AlbumsTable(iommi.Table):
    class Meta:
        auto__model = Album
        columns__name__filter__include = True
        columns__name__filter__freetext = True
        columns__artist__filter__include = True

And it works fine, until I "pre-define" freetext_search in either Style or "base" Table, like I explained here: https://github.com/iommirocks/iommi/issues/400#issuecomment-1541843091 https://github.com/iommirocks/iommi/issues/400#issuecomment-1541855711 Then for some reason the filtering on Artist stops working - I see the select2 in the filter form, but when I select an artist which has no albums, ajax still returns all albums. Same with accessing url ?artist=2, I also get all albums. (I tested with only one album and two artists)

I tracked it down to Query.on_bind (iommi/query.py) around the line with self.form = self.form.bind(parent=self)

        # keys(self.form.fields) = dict_keys(['freetext_search', 'name', 'year', 'artist'])
        self.form = self.form.bind(parent=self)
        # keys(self.form.fields) = dict_keys(['freetext_search'])

Or I just assume that's where it gets lost. Then I got lost and I wasn't really able to follow further, the code there is quite complicated for me yet :)