Skip to content

Commit

Permalink
Search form filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtraversy committed Sep 28, 2018
1 parent b45d881 commit bd1caf4
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 281 deletions.
34 changes: 33 additions & 1 deletion listings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,43 @@ def listing(request, listing_id):
return render(request, 'listings/listing.html', context)

def search(request):
queryset_list = Listing.objects.order_by('-list_date')

# Keywords
if 'keywords' in request.GET:
keywords = request.GET['keywords']
if keywords:
queryset_list = queryset_list.filter(description__icontains=keywords)

# City
if 'city' in request.GET:
city = request.GET['city']
if city:
queryset_list = queryset_list.filter(city__iexact=city)

# State
if 'state' in request.GET:
state = request.GET['state']
if state:
queryset_list = queryset_list.filter(state__iexact=state)

# Bedrooms
if 'bedrooms' in request.GET:
bedrooms = request.GET['bedrooms']
if bedrooms:
queryset_list = queryset_list.filter(bedrooms__lte=bedrooms)

# Price
if 'price' in request.GET:
price = request.GET['price']
if price:
queryset_list = queryset_list.filter(price__lte=price)

context = {
'state_choices': state_choices,
'bedroom_choices': bedroom_choices,
'price_choices': price_choices
'price_choices': price_choices,
'listings': queryset_list
}

return render(request, 'listings/search.html', context)
326 changes: 47 additions & 279 deletions templates/listings/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="container">
<div class="row text-center">
<div class="col-md-12">
<form action="search.html">
<form action="{% url 'search' %}">
<!-- Form Row 1 -->
<div class="form-row">
<div class="col-md-4 mb-3">
Expand Down Expand Up @@ -79,287 +79,55 @@
<section id="listings" class="py-4">
<div class="container">
<div class="row">

<!-- Listing 1 -->
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<img class="card-img-top" src="assets/img/homes/home-1.jpg" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">$490,000</span>
</h2>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<h4 class="text-primary">45 Drivewood Circle</h4>
<p>
<i class="fas fa-map-marker text-secondary"></i> Norwood MA, 02062</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-th-large"></i> Sqft: 3200</div>
<div class="col-6">
<i class="fas fa-car"></i> Garage: 2</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Bedrooms: 3</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: 2</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-12">
<i class="fas fa-user"></i> Kyle Brown</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> 2 days ago</div>
</div>
<hr>
<a href="listing.html" class="btn btn-primary btn-block">More Info</a>
</div>
</div>
</div>

<!-- Listing 2 -->
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<img class="card-img-top" src="assets/img/homes/home-2.jpg" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">$550,000</span>
</h2>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<h4 class="text-primary">18 Jefferson Lane</h4>
<p>
<i class="fas fa-map-marker text-secondary"></i> Woburn MA, 01801</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-th-large"></i> Sqft: 3200</div>
<div class="col-6">
<i class="fas fa-car"></i> Garage: 1</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Bedrooms: 4</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: 2.5</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-user"></i> Mark Hudson</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> 5 days ago</div>
{% if listings %}
{% for listing in listings %}
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<img class="card-img-top" src="{{ listing.photo_main.url }}" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">${{ listing.price | intcomma }}</span>
</h2>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<h4 class="text-primary">{{ listing.title }}</h4>
<p>
<i class="fas fa-map-marker text-secondary"></i> {{ listing.city }} {{ listing.state }}, {{ listing.zipcode }}</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-th-large"></i> Sqft: {{ listing.sqft }}</div>
<div class="col-6">
<i class="fas fa-car"></i> Garage: {{ listing.garage }}</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Bedrooms: {{ listing.bedrooms }}</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: {{ listing.bathrooms }}</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-12">
<i class="fas fa-user"></i> {{ listing.realtor }}</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> {{ listing.list_date | timesince }}</div>
</div>
<hr>
<a href="{% url 'listing' listing.id %}" class="btn btn-primary btn-block">More Info</a>
</div>
</div>
<hr>
<a href="listing.html" class="btn btn-primary btn-block">More Info</a>
</div>
{% endfor %}
{% else %}
<div class="col-md-12">
<p>No Listings Available</p>
</div>
</div>

<!-- Listing 3 -->
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<img class="card-img-top" src="assets/img/homes/home-3.jpg" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">$580,000</span>
</h2>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<h4 class="text-primary">187 Woodrow Street</h4>
<p>
<i class="fas fa-map-marker text-secondary"></i> Salem MA, 01915</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-th-large"></i> Sqft: 3107</div>
<div class="col-6">
<i class="fas fa-car"></i> Garage: 0</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Bedrooms: 4</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: 3</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-user"></i> Mark Hudson</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> 5 days ago</div>
</div>
<hr>
<a href="listing.html" class="btn btn-primary btn-block">More Info</a>
</div>
</div>
</div>

<!-- Listing 4 -->
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<img class="card-img-top" src="assets/img/homes/home-4.jpg" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">$380,000</span>
</h2>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<h4 class="text-primary">28 Gifford Street</h4>
<p>
<i class="fas fa-map-marker text-secondary"></i> Bedford NH, 03103</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-th-large"></i> Sqft: 2927</div>
<div class="col-6">
<i class="fas fa-car"></i> Garage: 2</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Bedrooms: 4</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: 2</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-user"></i> Jenny Johnson</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> 5 days ago</div>
</div>
<hr>
<a href="listing.html" class="btn btn-primary btn-block">More Info</a>
</div>
</div>
</div>

<!-- Listing 5 -->
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<img class="card-img-top" src="assets/img/homes/home-5.jpg" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">$230,000</span>
</h2>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<h4 class="text-primary">12 United Road</h4>
<p>
<i class="fas fa-map-marker text-secondary"></i> South Hampton NH, 03827</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-th-large"></i> Sqft: 2207</div>
<div class="col-6">
<i class="fas fa-car"></i> Garage: 1</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Bedrooms: 3</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: 1.5</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-user"></i> Kyle Brown</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> 5 days ago</div>
</div>
<hr>
<a href="listing.html" class="btn btn-primary btn-block">More Info</a>
</div>
</div>
</div>

<!-- Listing 6 -->
<div class="col-md-6 col-lg-4 mb-4">
<div class="card listing-preview">
<img class="card-img-top" src="assets/img/homes/home-6.jpg" alt="">
<div class="card-img-overlay">
<h2>
<span class="badge badge-secondary text-white">$780,000</span>
</h2>
</div>
<div class="card-body">
<div class="listing-heading text-center">
<h4 class="text-primary">33 Essex Circle</h4>
<p>
<i class="fas fa-map-marker text-secondary"></i> Lexington MA, 01731</p>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-th-large"></i> Sqft: 4145</div>
<div class="col-6">
<i class="fas fa-car"></i> Garage: 1</div>
</div>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-bed"></i> Bedrooms: 5</div>
<div class="col-6">
<i class="fas fa-bath"></i> Bathrooms: 3.5</div>
</div>
<hr>
<div class="row py-2 text-secondary">
<div class="col-6">
<i class="fas fa-user"></i> Kyle Brown</div>
</div>
<div class="row text-secondary pb-2">
<div class="col-6">
<i class="fas fa-clock"></i> 5 days ago</div>
</div>
<hr>
<a href="listing.html" class="btn btn-primary btn-block">More Info</a>
</div>
</div>
</div>

</div>

<div class="row">
<div class="col-md-12">
<ul class="pagination">
<li class="page-item disabled">
<a class="page-link" href="#">&laquo;</a>
</li>
<li class="page-item active">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item">
<a class="page-link" href="#">3</a>
</li>
<li class="page-item">
<a class="page-link" href="#">&raquo;</a>
</li>
</ul>
</div>
{% endif %}
</div>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h1 class="display-4 mb-4">
</select>
</div>
<div class="col-md-6 mb-3">
<select class="form-control" id="type">
<select name="price" class="form-control" id="type">
<option selected="true" disabled="disabled">Max Price (Any)</option>
{% for key,value in price_choices.items %}
<option value="{{ key }}">{{ value }}</option>
Expand Down

0 comments on commit bd1caf4

Please sign in to comment.