Account search w/ autocomplete

This commit is contained in:
Ludovic Stephan 2017-01-19 12:36:40 -02:00
parent eff37f6c89
commit e7956f3b62
3 changed files with 78 additions and 1 deletions

View file

@ -77,3 +77,29 @@ def account_create(request):
data['options'] = options
return render(request, "kfet/account_create_autocomplete.html", data)
def account_search(request):
if "q" not in request.GET:
raise Http404
q = request.GET.get("q")
words = q.split()
data = {'q': q}
for word in words:
query = Account.objects.filter(
Q(cofprofile__user__username__icontains=word) |
Q(cofprofile__user__first_name__icontains=word) |
Q(cofprofile__user__last_name__icontains=word)
).distinct()
query = [(account.trigramme, account.cofprofile.user.get_full_name())
for account in query]
data['accounts'] = query
options = len(query)
data['options'] = options
return render(request, 'kfet/account_search_autocomplete.html', data)