filtrowanie

This commit is contained in:
Jędrzej Klepacki 2020-12-06 16:13:09 +01:00
parent e92fb3ecf3
commit 5d72299c24
6 changed files with 68 additions and 6 deletions

View File

@ -119,6 +119,14 @@
</nav>
</div>
</div>
<form action="{% url 'filter' %}" method="post">
{% csrf_token %}
<input type="hidden" name="place" value="">
<input type="hidden" name="Oddam" value="">
<input type="hidden" name="Potrzebuje" value="">
<div class="col-lg-3 float-md-right">
<div class="categories_sidebar">
<aside class="l_widgest l_p_categories_widget">
@ -128,7 +136,11 @@
<ul class="navbar-nav">
<li class="nav-item">
<h3 class="cart_single_title">Miejscowość </h3>
<input type="text" placeholder="Miejscowość">
{% if place_local %}
<input type="text" name="place" placeholder="Miejscowość" value={{ place_local }}>
{% else %}
<input type="text" name="place" placeholder="Miejscowość" >
{% endif %}
</li>
</ul>
</aside>
@ -137,16 +149,27 @@
<h3>Typ</h3>
</div>
<ul>
{% if oddam_local %}
<input type="checkbox" id="Oddam" name="Oddam" Checked>
{% else %}
<input type="checkbox" id="Oddam" name="Oddam" >
{% endif %}
<label for="Oddam">Oddam</label>
<p></p>
{% if potrzebuje_local %}
<input type="checkbox" id="Potrzebuje" name="Potrzebuje" Checked>
{% else %}
<input type="checkbox" id="Potrzebuje" name="Potrzebuje" >
{% endif %}
<label for="scales">Potrzebuje</label>
</ul>
</aside>
<button type="submit" class="btn btn-primary update_btn">Zastosuj</button>
<input type="submit" class="btn btn-primary update_btn" value="Zastosuj">
</div>
</div>
</form>
</div>
</div>
</div>

View File

@ -3,4 +3,5 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path('filter', views.filter, name='filter'),
]

View File

@ -1,15 +1,53 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
from django.template import loader
from .models import Product, TYPE_T
def index(request):
all_product = Product.objects.all
template = loader.get_template('homepage/index.html')
types = TYPE_T
place_local = ""
oddam_local = ""
potrzebuje_local = ""
context = {
'all_product': all_product,
'types': types,
'place_local': place_local,
'oddam_local': oddam_local,
'potrzebuje_local': potrzebuje_local,
}
return HttpResponse(template.render(context, request))
def filter(request):
all_product = Product.objects.filter(create_date__contains = "2")
template = loader.get_template('homepage/index.html')
if request.method == 'POST':
place_local = request.POST['place']
oddam_local = request.POST['Oddam']
potrzebuje_local = request.POST['Potrzebuje']
if place_local != "":
all_product = all_product.filter(place=place_local)
if oddam_local == "on" and potrzebuje_local != "on":
zmienna = 2
all_product = all_product.filter(type=zmienna)
if oddam_local != "on" and potrzebuje_local == "on":
zmienna = 1
all_product = all_product.filter(type=zmienna)
types = TYPE_T
print(types)
context = {
'all_product': all_product,
'types': types,
'place_local': place_local,
'oddam_local': oddam_local,
'potrzebuje_local': potrzebuje_local,
}
return HttpResponse(template.render(context, request))