Based on this approach, i want built a dynamic filter with multiple and_ and or_ levels. My filter conditions looks like this:
filters = [{Contact.shown_name: 'a', Contact.town: 'b'}, {Contact.shown_name: 'c'}]
The conditions in one dictionary should be in a AND-clause. The dictionarys itself should be in an OR-clause.
I want the result from this filter:
.filter(or_(and_(Contact.shown_name.ilike('%a%'), Contact.town.ilike('%b%')),
and_(Contact.shown_name.ilike('%c%'))))
I want to filter all items where the shown_name contains 'a' and the town contains 'b' OR all items where the shown_name contains 'c'.
The number of condition and dictionarys in the list 'filters' is flexible.
How can I do it?