File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ <h1>Welcome to the Pacific Connect Community Database</h1>
55 On this site, you can find details of members of the Pacific Connect Community Database
66 < br >
77 < form >
8- {{ form.as_p }}
8+ < label for ="id-search "> Search:</ label >
9+ < input type ="text " name ="search " id ="id-search ">
910 < input type ="submit ">
1011 </ form >
1112 {% if search_text %}
Original file line number Diff line number Diff line change 11{% extends "base.html" %}
22
33{% block content %}
4- This is my list of folks
5- < ul >
6- {% for person in object_list %}
7- < li >
8- < a href ="{% url 'fbv-person-detail' person.id %} ">
9- {{ person.first_name }} {{ person.last_name }}
10- </ a > from {{ person.country }}
11- </ li >
12- {% endfor %}
13- </ ul >
14- {% endblock %}
4+ {% if object_list %}
5+ This is my list of folks
6+ < ul >
7+ {% for person in object_list %}
8+ < li >
9+ < a href ="{% url 'fbv-person-detail' person.id %} ">
10+ {{ person.first_name }} {{ person.last_name }}
11+ </ a > from {{ person.country }}
12+ </ li >
13+ {% endfor %}
14+ </ ul >
15+ {% else %}
16+ No profiles match that search
17+ {% endif %}
18+ {% endblock %}
Original file line number Diff line number Diff line change 22from django .shortcuts import render
33from django .views .generic import DetailView , ListView
44
5- from .forms import QuickSearchForm
65from .models import Person
76
87# FUNCTION BASED VIEWS
98
10- # Searching the first name and last name fields using a Django form
9+ # Searching the first name and last name fields with text in the search box
1110def list_persons_with_template (request ):
12- form = QuickSearchForm ( request .GET )
11+ search_text = request .GET . get ( "search" )
1312
1413 persons = Person .objects .all ()
15- search_text = ""
16- if form .is_valid ():
17- search_text = form .cleaned_data ["search" ]
18- if search_text :
19- search_filters = models .Q (first_name__icontains = search_text ) | models .Q (
20- last_name__icontains = search_text
21- )
22- persons = persons .filter (search_filters )
23- context = {"object_list" : persons , "search_text" : search_text , "form" : form }
14+ if search_text :
15+ search_filters = models .Q (first_name__icontains = search_text ) | models .Q (
16+ last_name__icontains = search_text
17+ )
18+ persons = persons .filter (search_filters )
19+ context = {"object_list" : persons , "search_text" : search_text }
2420 return render (request , "community_db/person_list_in_base.html" , context )
2521
2622
You can’t perform that action at this time.
0 commit comments