码迷,mamicode.com
首页 > 其他好文 > 详细

Django的筛选功能

时间:2017-12-26 20:59:54      阅读:478      评论:0      收藏:0      [点我收藏+]

标签:cti   ref   request   django   高校   类别   _id   obj   str   

<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的筛选功能

标签:cti   ref   request   django   高校   类别   _id   obj   str   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!