首页 > 其他 > 详细

Django的筛选功能

时间:2017-12-26 20:45:20      阅读:274      评论:0      收藏:0      [点我收藏+]
<li>
<h2>机构类别</h2>
<div class="cont">
<a href="?city={{ city_id }}"><span class="{% ifequal category ‘‘ %}active2{% endifequal %}">全部</span></a>

<a href="?ct=pxjg&city={{ city_id }}"><span class="{% ifequal category ‘pxjg‘ %}active2{% endifequal %}">培训机构</span></a>

<a href="?ct=gx&city={{ city_id }}"><span class="{% ifequal category ‘gx‘ %}active2{% endifequal %}">高校</span></a>

<a href="?ct=gr&city={{ city_id }}"><span class="{% ifequal category ‘gr‘ %}active2{% endifequal %}">个人</span></a>

</div>
</li>
<li>
<h2>所在地区</h2>
<div class="more">更多</div>
<div class="cont">
<a href="?ct={{ category }}"><span class="{% ifequal city_id ‘‘ %}active2{% endifequal %}">全部</span></a>
{% for city in all_city %}
<a href="?city={{ city.id }}&ct={{ category }}"><span class="{% ifequal city_id city.id|stringformat:"i" %}active2{% endifequal %}">{{ city.name }}</span></a>
{% endfor %}
</div>

def get(self,request):
#课程机构
all_orgs = CourseOrg.objects.all()
hot_orgs = all_orgs.order_by("-click_nums")[:3]
#取出筛选城市
city_id = request.GET.get(‘city‘,‘‘)
if city_id:
all_orgs = all_orgs.filter(city_id=int(city_id))

#城市
all_city = CityDict.objects.all()
#机构类别筛选
category = request.GET.get(‘ct‘, ‘‘)
if category:
all_orgs = all_orgs.filter(category=category)



Django的筛选功能

原文:https://www.cnblogs.com/onlyhold/p/8119780.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!