[Django]-Django queryset of reverse manytomany relation

4👍

You can do it in one query. This would give you a respondents who have answered a question in a specific topic.

respondants = Respondant.objects.filter(answer__question__topic__name = name)

Or if you have a topic object,

respondants = Respondant.objects.filter(answer__question__topic = topic)

You can read more on lookups that span relationships here

Leave a comment