Skip to content

Commit

Permalink
Remove duplicate entries in autocomplete (#356)
Browse files Browse the repository at this point in the history
When "autocomplete_search_fields" contains a ManyToMany related field, the resulting queryset has duplicates. Adding a distinct() removes them.
  • Loading branch information
lmwgv authored and f1nality committed Oct 18, 2018
1 parent 266b0ac commit f3ca18f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jet/forms.py
Expand Up @@ -134,7 +134,7 @@ def lookup(self):
filter_data = [Q((field + '__icontains', self.cleaned_data['q'])) for field in search_fields]
# if self.cleaned_data['object_id']:
# filter_data.append(Q(pk=self.cleaned_data['object_id']))
qs = qs.filter(reduce(operator.or_, filter_data))
qs = qs.filter(reduce(operator.or_, filter_data)).distinct()
else:
qs = qs.none()

Expand All @@ -148,4 +148,4 @@ def lookup(self):
))
total = qs.count()

return items, total
return items, total

0 comments on commit f3ca18f

Please sign in to comment.