在django搜索中没有得到结果,但个人搜索运行良好



我的问题是,当我向单个搜索字段添加简单功能时,它对单个搜索字段运行良好,就像在添加位置字段的功能后,它按我的意愿运行,但在为另一个字段添加另一个功能后,即使第一个字段也不显示结果,我认为这是一个非常愚蠢的问题,但我想不通,请帮我编代码!(我添加了html和views.py代码,如果你需要其他东西,请告诉我guyz(

html代码

<form action="{% url 'search-page' %}" method="">
<div class="row">
<div class="col-12 col-lg-10">
<div class="row">
<div class="col-12 col-md-6 col-lg-3">
<select name="location" id="location" class="form-control">
<option value="">Location</option>
{% for key,value in location_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 col-md-6 col-lg-3">
<select name="types" id="types" class="form-control">
<option value="all-types">All Types</option>
{% for key,value in property_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 col-md-6 col-lg-3">
<select name="city" id="city" class="form-control">
<option value="01">All City</option>
{% for key,value in city_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 col-md-6 col-lg-3">
<select name="status" id="all" class="form-control">
<option value="01">Status</option>
{% for key,value in status_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 col-md-6 col-lg-3">
<select name="bedroom" id="bedrooms" class="form-control">
<option value="">Bedrooms</option>
{% for key,value in bedroom_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 col-md-6 col-lg-3">
<select name="bathroom" id="bathroom" class="form-control">
<option value="Bathroom">Bathroom</option>
{% for key,value in bathroom_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 col-md-6 col-lg-3">
<select name="price" id="bathroom" class="form-control">
<option value="Bathroom">Price</option>
{% for key,value in price_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 col-md-6 col-lg-3">
<select name="size" id="bathroom" class="form-control">
<option value="Bathroom">Lot Size</option>
{% for key,value in lot_area_choices.items %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>
<!-- <div class="col-12 col-md-6 col-lg-3">
<div class="slider-range mb-15">
<div class="range-price text-white">Price [30000 - 150000]$</div>
<div class="slider-range-price ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"
data-min="0" data-max="200000" data-unit="$" data-value-min="30000"
data-value-max="150000" data-label-result="Price">
<div class="ui-slider-range ui-widget-header ui-corner-all"></div>
<span class="ui-slider-handle ui-state-default ui-corner-all"
tabindex="0"></span>
<span class="ui-slider-handle ui-state-default ui-corner-all"
tabindex="0"></span>
</div>
</div>
</div> -->
<!-- <div class="col-12 col-md-6 col-lg-3">
<div class="slider-range mb-15">
<div class="range-size text-white">Size [9762 - 72063]sqFt</div>
<div data-min="0" data-max="98623" data-unit="sqFt"
class="slider-range-size ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"
data-value-min="9762" data-value-max="72063" data-label-result="Size">
<div class="ui-slider-range ui-widget-header ui-corner-all"></div>
<span class="ui-slider-handle ui-state-default ui-corner-all"
tabindex="0"></span>
<span class="ui-slider-handle ui-state-default ui-corner-all"
tabindex="0"></span>
</div>
</div>
</div> -->
</div>
</div>
<div class="col-12 col-lg-2">
<button type="submit" class="btn rehomes-search-btn">Search</button>
</div>
</div>
</form>

视图.py

def search(request):
property_list = Property.objects.order_by('-date_added')
# Search_location
if 'location' in request.GET:
location = request.GET['location']
if location:
property_list = property_list.filter(state__iexact=location)
# Search_types
if 'types' in request.GET:
types = request.GET['types']
if types:
property_list = property_list.filter(property_types__iexact=types)
# Search_status
if 'bedroom' in request.GET:
bedroom = request.GET['bedroom']
if bedroom:
property_list = property_list.filter(bedroom__lte=bedroom)
context = {
'property_data': property_list,
'location_choices': choices.location_choices,
'property_choices': choices.property_choices,
'city_choices': choices.city_choices,
'status_choices': choices.status_choices,
'bedroom_choices': choices.bedroom_choices,
'bathroom_choices': choices.bathroom_choices,
'price_choices': choices.price_choices,
'lot_area_choices': choices.lot_area_choices
}
return render(request, 'property/search.html', context)
if 'location' in request.GET:
location = request.GET['location']
if location:
property_list = property_list.filter(state__iexact=location)
# Search_types
if 'types' in request.GET:
types = request.GET['types']
if types:
property_list = property_list.filter(property_types__iexact=types)
# Search_status
if 'bedroom' in request.GET:
bedroom = request.GET['bedroom']
if bedroom:
property_list = property_list.filter(bedroom__lte=bedroom)

最新更新