TandoorRecipes/cookbook/helper/dal.py
2018-03-31 11:29:18 +02:00

17 lines
378 B
Python

from dal import autocomplete
from cookbook.models import Keyword
class KeywordAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
if not self.request.user.is_authenticated:
return Keyword.objects.none()
qs = Keyword.objects.all()
if self.q:
qs = qs.filter(name__istartswith=self.q)
return qs