Django filter that spans relationships but programmatically?

django, django-models, relation

Solution

You can make a dictionary and unpack it into the keyword arguments:

filters = {'entry__headline__contains': 'Lennon'}
Blog.objects.filter(**filters)  

where `entry__headline__contains` can be dynamically evaluated.

Problem

I understand that to span a relationship in a Django filter you use a double underscore like this: ``` Blog.objects.filter(entry__headline__contains='Lennon') ``` However, I have a bunch of dynamic filters that will be determined at runtime. Can I achieve the same as the above but programmatically?

Original source