[py][mx]django实现根据城市和课程机构类别过滤
实现根据城市&课程机构过滤
实现点谁谁高亮,支持取交集.

直接上代码吧
本质上是过滤,多层过滤,取交集
def get(self, request):
all_orgs = CourseOrg.objects.all() # 所有课程机构
all_citys = CityDict.objects.all() # 所有城市列表
# 取出筛选城市
city_id = request.GET.get("city", "")
if city_id:
all_orgs = all_orgs.filter(city_id=int(city_id))
# 取出筛选培训机构
category = request.GET.get('ct', "")
if category:
all_orgs = all_orgs.filter(category=category)
org_nums = all_orgs.count() # 多少家课程机构
class OrgView(View): # 课程机构列表页
def get(self, request):
all_orgs = CourseOrg.objects.all() # 所有课程机构
all_citys = CityDict.objects.all() # 所有城市列表
# 取出筛选城市
city_id = request.GET.get("city", "")#前端传递来city.id
if city_id:
all_orgs = all_orgs.filter(city_id=int(city_id))
# 取出筛选培训机构
category = request.GET.get('ct', "")#前端传来ct类型
if category:
all_orgs = all_orgs.filter(category=category)
org_nums = all_orgs.count() # 多少家课程机构
# 分页模块
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
# all_orgs = ['john', 'edward', 'josh', 'frank']
# Provide Paginator with the request object for complete querystring generation
p = Paginator(all_orgs, 3, request=request)
orgs = p.page(page)
return render(request, 'org-list.html', {
"all_orgs": orgs,
"all_citys": all_citys,
'org_count': org_nums,
'city_id': city_id,#将city_id传回去
'category': category,#将category传回去
})
org-list.html
{% extends 'base.html' %}{# 一定要出现在第一行 #}
{% load staticfiles %}
{% block title %}
课程列表
{% endblock %}
{% block custom_bread %}
<div>
<ul>
<li><a href="">首页</a>>课程机构</li>
</ul>
</div>
{% endblock %}
{% block content %}
{# 机构类别 #}
<div>
<strong>机构类别</strong>:
<a href="?city={{ city_id }}"><span class="{% ifequal category '' %}bgColor{% endifequal %}">全部</span></a>
<a href="?ct=pxjg&city={{ city_id }}"><span class="{% ifequal category 'pxjg' %}bgColor{% endifequal %}">培训机构</span></a>
<a href="?ct=gx&city={{ city_id }}"><span class="{% ifequal category 'gx' %}bgColor{% endifequal %}">高校</span></a>
<a href="?ct=gr&city={{ city_id }}"><span class="{% ifequal category 'gr' %}bgColor{% endifequal %}">个人</span></a>
</div>
{# 城市 #}
<div>
<p><strong>城市:</strong>
<span class="{% ifequal city_id '' %}bgColor{% endifequal %}"><a href="?ct={{ category }}">全部</a></span>
{% for city in all_citys %}
<span class="{% ifequal city_id city.id|stringformat:'i' %}bgColor{% endifequal %}"><a
href="?city={{ city.id }}&ct={{ category }}">{{ city.name }}</a></span>
{% endfor %}
</p>
</div>
{# 课程机构 #}
<div>
<strong>共{{ org_count }}家</strong>
<ul>
{% for course_org in all_orgs.object_list %}
<li><img src="{{ MEDIA_URL }}{{ course_org.image }}" alt=""></li>
<li>{{ course_org }}</li>
{% endfor %}
</ul>
<p>{{ all_orgs.render }}</p>
</div>
{% endblock %}
这部分
这里city.id是整形,需要django tmpl的方法|stringformat:'i'将前面参数转换为整数后再比较
哪个citry_id,即显示哪个
class="{% ifequal city_id city.id|stringformat:'i' %}bgColor{% endifequal %}"
[py][mx]django实现根据城市和课程机构类别过滤的更多相关文章
- [py][mx]django课程页显示city和机构封面图
city和课程机构信息展示到前台去 organization/views.py from django.views.generic.base import View from organization ...
- [py][mx]django添加后台课程机构页数据-图片上传设置
分析下课程页前台部分 机构类别-目前机构库中没有这个字段,需要追加下 所在地区 xadmin可以手动添加 课程机构 涉及到机构封面图, 即图片上传media设置, 也需要在xadmin里手动添加几条 ...
- [py][mx]django模板继承-课程列表页
课程列表页分析 1,机构类型 2,所在地区 3.排序 学习人数 先分析下 纵观页面,页头页脚都一样. django提供了模板继承. 至少 不同页面的title 面包屑路径 content内容不一致,以 ...
- [py][mx]django城市-教学机构-教师模型设计
分析下城市-教学机构-教师模型设计 CourseOrg 课程信息 Teacher 教师信息 CityDict 城市信息 代码 from datetime import datetime from dj ...
- [py][mx]django实现课程机构排名
如果是第一次做这个玩意,说实话,确实不知道怎么弄, 做一次后就有感觉了 此前我们已经完成了: 分类筛选 分页 这次我们做的是 课程机构排名 知识点: - 按照点击数从大到小排名, 取出前三名 hot_ ...
- [py][mx]django分页第三方模块django-pure-pagination
前台的这些数据都是从后台取来的 分页模块django-pure-pagination - 一款基于django pagination封装的更好用的分页模块 https://github.com/jam ...
- [py][mx]django项目-让系统用自定义的users表认证
项目开端 参考的是mxonline项目 先把这两项完成 1.app设计 2.app的models的设计 经过分析系统有四个模块 users - 用户管理 course - 课程管理 oranizati ...
- [py][mx]django处理登录逻辑
浏览器同源策略(same-origin policy) csrf攻击防御核心点总结 django的cookie和session操作-7天免登录 flask操作cookie&django的see ...
- [py][mx]django自定义认证类-实现邮箱作为用户名登录
创建自定义验证用户名密码类CustomBackend users/views.py from django.contrib.auth import authenticate, login from d ...
随机推荐
- matlab imresize 改变图像大小
功能:改变图像的大小. 用法:B = imresize(A,m)B = imresize(A,m,method)B = imresize(A,[mrows ncols],method) B = imr ...
- linux,shell脚本中获取脚本的名字,使用脚本的名字。
需求描述: 写shell脚本的过程中,有时会需要获取脚本的名字,比如,有的时候,脚本 中会有usage()这种函数,可能就会用到脚本的名字. 实现方法: shell脚本中,通过使用$0就可以获取到脚本 ...
- brew 的 调度工具DBGPRINTF 和 c语言的 printf
在官方的文档中是这样备注DBGPRINTF Prototype void dbgprintf(const char *pszFormat,...); Description This function ...
- ios 判断GPS是否是在中国境内
博文转载至 http://blog.csdn.net/cuibo1123/article/details/45691631 ZCChinaLocation 基本思路是:把整个行政区域划分为几个小的矩形 ...
- Linux上Nginx部署配置--二级域名配置
http://www.cnblogs.com/yaunion/archive/2013/03/16/2962385.html http://blog.csdn.net/LBinin/article/d ...
- Cesium - 离线使用方法
使用Cesium可以直观的看基于DEM切片产生的Terrain地形数据,有种身临其境的感觉,但缺点是Cesium默认缺省加载了微软Bing提供的地形以及遥感影像数据,可以跟踪日志,总提示让你申请微软的 ...
- python2.0_day19_充分使用Django_form实现前端操作后台数据库
在前面的<python2.0_day19_学员管理系统之前端用户交互系统>一节中,我们实现了前端展示customer客户纪录.在<python2.0_day19_前端分页功能的实现& ...
- Vitamio与FFmpeg、LGPL、GPL的关系
转自:http://sun.sanniang.me/2014/04/26/the-relationship-vitamio-with-ffmepg-lgp-gpl Vitamio 使用了 FFmpeg ...
- PyQt4预定义对话框
PyQt4中的对话框 对话窗口和对话框是现代GUI应用程序必不可少的一部分.生活中“对话”被定义为发生在两人或更多人之间的会话.而在计算机世界,“对话”则时人与应用程序之间的“会话”.人及对话的形式有 ...
- mysql 效率 inner join 与 where in
-- report 123.77k行 report_loss 620 行 -- inner join ;report_loss 索引 all report 索引 eq_ref ; -- total 0 ...