[Answered ]-Get QuerySets from Many2ManyField (include related fields)

2👍

[Your qn shows a ‘Thread’ model but then goes on to refer to ‘listing_set’ in your wokring code – I assume this is a typo?]

You could use Q objects. Assuming that your Board model has a ‘name’ field containing the board name, I believe the following should work:

from django.db.models import Q
Thread.objects.filter(Q(board__parent_board__name='Computing') | Q(name='Computing'))

The first Q object selects threads which are part of a board which has ‘parent_board’ set to a board with name ‘Computing’. The second Q object selects threads which are directly part of a board which has the name ‘Computing’.

Leave a comment