Django 1.10.1
On a page I have prepared a lot of controls. Some of them are organized as dynamically changing formsets. So, I don't even know how many of them are present.
I need a chained filters with AND, OR and NOT logical operations.
For example, I need something like this:
Entry.objects.filter(headline__startswith='What').exclude(pub_date__gte=datetime.date.today()).filter(pub_date__gte=datetime(2005, 1, 30)).filter(Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
Once more the number of filters is changing.
I was planning to ac like that: loop through request.POST and depending on a dozen of conditions prepare a string. The same string:
"Entry.objects.filter(headline__startswith='What').exclude(pub_date__gte=datetime.date.today()).filter(pub_date__gte=datetime(2005, 1, 30)).filter(Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))"
So, the string is correct. But I can't make it work with exec(). I asked here: why it is not working. And the answer was: it will not work, run the Python code directly.
I can construct something like that:
entries = Entry.objects.filter( **kwargs )
But this is just one filter. I can't imagine how to chain such filters.
Could you help me here&