[Answered ]-How to transform QuerySet to another type?

1👍

You can filter with:

Network.objects.filter(members__user=self.user)

One can use double underscores (__) to look "through" relations. Since you specified the related_name='members', we access the relation in reverse.

If there are multiple NetworkMembers with the same user to the same Network, then that Network will be returned that many times as there are such NetworkMember‘s, you can use .distinct() [Django-doc] to prevent that:

Network.objects.filter(members__user=self.user).distinct()

Leave a comment