added custom autocomplete for category in product admin, still not working correctly

This commit is contained in:
Sam
2021-03-04 13:23:11 +00:00
parent 657b717c07
commit 085c6f86a7
4 changed files with 18 additions and 19 deletions

View File

@@ -223,12 +223,11 @@ class CategoryTagAutocomplete(autocomplete.Select2QuerySetView):
Tag = Product.category.tag_model
# Return nothing if not auth
if not self.request.is_authenticated():
if self.request.user.is_anonymous:
return Tag.objects.none()
qs = Tag.objects.all()
if self.q:
qs = qs.filter(name__istartswith=self.q)
qs = qs.filter(name__icontains=self.q)
return self.q
return qs # [x.label for x in qs]