Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions dojo/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,34 @@ def __init__(self, *args, **kwargs):
if exclude:
self.form.fields[field].label = "Not " + self.form.fields[field].label

def filter_queryset(self, queryset):
qs = super().filter_queryset(queryset)
if hasattr(self, "form") and hasattr(self.form, "cleaned_data"):
for name, f in self.filters.items():
field_name = getattr(f, "field_name", "") or ""
# Only apply distinct for tag lookups that can duplicate base rows
if "tags__name" in field_name:
value = self.form.cleaned_data.get(name, None)
if value not in (None, "", [], (), {}):
lookup_expr = getattr(f, "lookup_expr", None)
is_exclude = getattr(f, "exclude", False)
needs_distinct = (
is_exclude
or lookup_expr in {
"in",
"contains",
"icontains",
"startswith",
"istartswith",
"endswith",
"iendswith",
}
)
# exact/iexact typically won't duplicate rows
if needs_distinct:
return qs.distinct()
return qs


def get_tags_model_from_field_name(field):
exclude = False
Expand Down