2

sorry, I can't imagine better title for my question

I have two filters

themes = Theme.objects.filter(grade = st.grade) # returns many objects
tests = Test.objects.filter(theme=themes) 

I want to return all objects, that equal to any object from themes, but it returns only objects then equal to first object from themes

2 Answers 2

3

If theme in Test is ForeignKey to Theme, you can do it in one query:

tests = Test.objects.filter(theme__grade=st.grade)
Sign up to request clarification or add additional context in comments.

Comments

2

Use in:

tests = Test.objects.filter(theme__in=themes)

Comments

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.