[Answered ]-Django – Mulitple excludes in template filter

2πŸ‘

βœ…

This would work:

{% exclude_files_by_type Site.sitefiles_set.all "Site Plan, Cabinet Photo" as files %}

and your assignment tag:

@register.assignment_tag
def exclude_files_by_type(SiteFiles, types):
    type_list = [type.strip() for type in types.split(',')]
    return SiteFiles.exclude(file_type__type__in=type_list)

To add more types to the exclusion query you should place them in the argument separated by commas:

{% exclude_files_by_type Site.sitefiles_set.all "Site Plan, Cabinet Photo, Last Summer, Group Selfies" as files %}

Leave a comment