Search code examples
djangodjango-templatesdjango-appsdjango-tagging

django-tagging only show tags from filtered items


I was wondering how you can filter an object in django-tagging.

For instance if you have written an article and the status is still draft you obviously don't want to show these before the article has been pushed to a live status.

Do you do it in the {% tags_for_model products.Widget as widget_tags %} or is there another way?


Solution

  • You could do it by using usage_for_model in your view you can add filters e.g.

    Tag.objects.usage_for_model(ModelClass, filters={"status":1})
    

    or create a version of tags_for_model that accepts filters