Skip to content

Commit

Permalink
search contact by name, title or organization
Browse files Browse the repository at this point in the history
closes #22
  • Loading branch information
ZendaInnocent committed Nov 5, 2023
1 parent 69ec800 commit 3e8fbee
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pim/contacts/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.db.models import Q
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
Expand Down Expand Up @@ -77,7 +78,9 @@ def contact_search(request: HttpRequest) -> TemplateResponse:
q = request.GET.get('q', None)
contacts = []
if q is not None:
contacts = request.user.contacts.filter(name__icontains=q)
contacts = request.user.contacts.filter(
Q(name__icontains=q) | Q(title__icontains=q) | Q(organization__icontains=q)
)

return TemplateResponse(
request, 'contacts/contact_list.html', {'contacts': contacts}
Expand Down

0 comments on commit 3e8fbee

Please sign in to comment.