1

I have a little problem.

I'm trying to use django filter e.g. SomeTable.objects.filter(someParam="something") this is working well but...

What if i have param name like string in some variable like: test="someParam".

How to now call filter function? I tried SomeTable.objects.filter(eval(test)="something") but seems not working...

1 Answer 1

3

Because filter arbitrary number of arguments using **kwargs this should work:

test="someParam"
SomeTable.objects.filter(**{test: "something"})
Sign up to request clarification or add additional context in comments.

2 Comments

Just another thing... How to call __iexact function on that parameter?
Try: SomeTable.objects.filter(**{test + '__iexact': "something"})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.