[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 ...
随机推荐
- Linux Shell脚本面试25个经典问答
1 Shell脚本是什么.它是必需的吗? 答:一个Shell脚本是一个文本文件,包含一个或多个命令.作为系统管理员,我们经常需要使用多个命令来完成一项任务,我们可以添加这些所有命令在一个文本文件(Sh ...
- RecyclerView的通用适配器,和滚动时不加载图片的封装
对于RecyclerView我们需要使用RecyclerAdapter,使用方式与ListViewAdapter类似,具体代码大家可以在网上搜索,这里就只教大家使用封装后的简洁RecyclerAdap ...
- Unity中SendMessage和Delegate效率比较
网上直接搜的代码.需要的使用也简单,所以就不过多说明. 但是网上都说,他们之间的差距,delegate比较快,效果高.怎么个高法呢?还是自己来测试下时间. 故此, 个人之用来比较下时间差别. 一.直接 ...
- Android 监听按钮的点击事件
onClick事件1.Button和ImageButton都拥有一个onClick事件 通过自身的.setOnClickListener(OnClickListener)方法添加点击事件2.所有的控件 ...
- php查询操作实现投票功能
这篇文章主要为大家详细介绍了php查询操作实现投票功能的具体代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本文实例为大家分享了php查询操作实现投票功能的代码,供大家参考,具体内容如下 ...
- 打造不死的asp木马
作者:黑色记忆本文已发表于<黑客X档案>杂志第十期 版权归<黑客X档案>所有 转载请注明版权 想不到,前几天我才发现,我千辛万苦收集的asp木马,居然没有几个不被Kill的.常 ...
- AndroidのUI体验之上拉下拉
1.ScrollView监测是否滚动到顶部或底部 onScrollChanged(); 滚动到顶部判断:getScrollY() == 0 滚动到底部判断:getChildAt(0).getMeasu ...
- 【Mysql】大数据处理优化方法
1.应尽量避免在 where 子句中使用 != 或 <> 操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 orde ...
- Ubuntu 12.04 部署 PostGIS 2.1
首先,卸载掉原有的postgis和postgresql-9.1-postgis,不然你就用1.5版好了~ 1 sudo dpkg --purge postgis postgresql-9.1-post ...
- java基础----->TCP和UDP套接字编程
这里简单的总结一下TCP和UDP编程的写法,另外涉及到HttpUrlConnection的用法 . TCP套接字 一.项目的流程如下说明: .客户输入一行字符,通过其套接字发送到服务器. .服务器从其 ...