[Fixed]-How to filter objects in ManyToMany field back reference?

1👍

✅

I did it like this:

def tags(request):
    published_tags = Tag.objects\
        .filter(is_published=True, posts__is_published=True)\
        .exclude(posts=None)\
        .order_by('name')\
        .distinct()
    return {'tags': published_tags}

ps: https://en.wikipedia.org/wiki/Rubber_duck_debugging

Leave a comment