[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 ...
随机推荐
- 在Office上怎么用MathType编辑公式
随着无纸化的办公程序越来越深入普及到社会的各个层面,很多资料都是电子档.从前手写的内容全都转换到了电脑上.用Office办公时,有一个很大的问题,那就是其中的公式要怎么编辑? 从前用手写毫无困难,什么 ...
- 实例教程Unity3D单例模式(二)自我包括法
unity3d 里的单例模式自我包括法 有一次玩Trench Run game,我意识到我的场景类里存在很多的GameObject.所以,我开发了自我包括的单例.假设没找找到实例,就会创建它自己的Ga ...
- 使用select多选标签笔记
之前一直用checkbox做多选,其实 select也可以多选,只要多给一个属性即可.标签属性 http://www.w3school.com.cn/tags/att_select_multiple. ...
- shell基础篇(十)shell脚本的包含
前记 写到这里:shell中基础差不多已经讲完了.希望你已经对shell有了一个基本了解.你可能跃跃欲试,要写一些程序练习一下.这会对你很有好处.建议大家去chinaunix去学习:我是li0924. ...
- Redis(五)-- Java API
一.pox.xml <dependencies> <dependency> <groupId>redis.clients</groupId> <a ...
- Eclipse版GoogleI/O2014开源项目
https://github.com/google/iosched谷歌原版是Gradle工程,用Eclipse开发的导入不了,所以搞了一个Elicpse工程,依赖的jar.库比较多,也比较难找... ...
- 使用boch仿真器在x86 PC平台上搭建Linux0.11系统环境(windows下)
当你有机会来到这页面时 十有八九是遇到这样一个问题 执行配置文件bochsrc_fd.bxrc时出现找不到 ips的情况! 版本原因吧 将boch版本换成2.4的问题就迎刃而解了~ 简单 ...
- LeetCode——Add Digits
Description: Given a non-negative integer num, repeatedly add all its digits until the result has on ...
- hdu5305 Friends[状压dp]
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 设备信息的管理(Device) ---- HTML5+
模块:Device Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI.IMSI.型号.厂商等.通过plus.device获取设备信息管理对象. 应用场景:打电话,铃声提醒,震动提醒 ...