[Django]-Django – Build a model filter from string

10👍

Yes. Use your strings as the keys and values of a dictionary, then pass that dictionary to filter using the ** operator to use them as keyword argument pairs. Using your above example:

filter_arguments = {query: x}
some_model.filter(**filter_arguments)

Leave a comment