forked from DGNum/gestioCOF
Account search w/ autocomplete
This commit is contained in:
parent
eff37f6c89
commit
e7956f3b62
3 changed files with 78 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue