diff --git a/src/community_db/templates/base.html b/src/community_db/templates/base.html index 666ebf8..96c5da4 100644 --- a/src/community_db/templates/base.html +++ b/src/community_db/templates/base.html @@ -5,7 +5,8 @@

Welcome to the Pacific Connect Community Database

On this site, you can find details of members of the Pacific Connect Community Database
- {{ form.as_p }} + +
{% if search_text %} diff --git a/src/community_db/templates/community_db/person_list_in_base.html b/src/community_db/templates/community_db/person_list_in_base.html index d9d4ede..d003e30 100644 --- a/src/community_db/templates/community_db/person_list_in_base.html +++ b/src/community_db/templates/community_db/person_list_in_base.html @@ -1,14 +1,18 @@ {% extends "base.html" %} {% block content %} - This is my list of folks - -{% endblock %} \ No newline at end of file + {% if object_list %} + This is my list of folks + + {% else %} + No profiles match that search + {% endif %} +{% endblock %} diff --git a/src/community_db/views.py b/src/community_db/views.py index e46dccc..56ebb50 100644 --- a/src/community_db/views.py +++ b/src/community_db/views.py @@ -2,25 +2,21 @@ from django.shortcuts import render from django.views.generic import DetailView, ListView -from .forms import QuickSearchForm from .models import Person # FUNCTION BASED VIEWS -# Searching the first name and last name fields using a Django form +# Searching the first name and last name fields with text in the search box def list_persons_with_template(request): - form = QuickSearchForm(request.GET) + search_text = request.GET.get("search") persons = Person.objects.all() - search_text = "" - if form.is_valid(): - search_text = form.cleaned_data["search"] - if search_text: - search_filters = models.Q(first_name__icontains=search_text) | models.Q( - last_name__icontains=search_text - ) - persons = persons.filter(search_filters) - context = {"object_list": persons, "search_text": search_text, "form": form} + if search_text: + search_filters = models.Q(first_name__icontains=search_text) | models.Q( + last_name__icontains=search_text + ) + persons = persons.filter(search_filters) + context = {"object_list": persons, "search_text": search_text} return render(request, "community_db/person_list_in_base.html", context)