[Answer]-Django model manytomany filter

1👍

This should work:

Newsletter.objects.filter(
    id__in=[subscription.newsletter.id for subscription in
            Subscription.objects.filter(subscriber=user)]

More readable(and verbose) version:

subscriptions = Subscription.objects.filter(subscriber=user) # all subscriptions for a given user

newsletter_ids = [subscription.newsletter.id for subscription in subscriptions]

Newsletter.objects.filter(id__in=newsletter_ids) # answer

Leave a comment