实现根据城市&课程机构过滤

实现点谁谁高亮,支持取交集.

直接上代码吧

本质上是过滤,多层过滤,取交集

    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实现根据城市和课程机构类别过滤的更多相关文章

  1. [py][mx]django课程页显示city和机构封面图

    city和课程机构信息展示到前台去 organization/views.py from django.views.generic.base import View from organization ...

  2. [py][mx]django添加后台课程机构页数据-图片上传设置

    分析下课程页前台部分 机构类别-目前机构库中没有这个字段,需要追加下 所在地区 xadmin可以手动添加 课程机构 涉及到机构封面图, 即图片上传media设置, 也需要在xadmin里手动添加几条 ...

  3. [py][mx]django模板继承-课程列表页

    课程列表页分析 1,机构类型 2,所在地区 3.排序 学习人数 先分析下 纵观页面,页头页脚都一样. django提供了模板继承. 至少 不同页面的title 面包屑路径 content内容不一致,以 ...

  4. [py][mx]django城市-教学机构-教师模型设计

    分析下城市-教学机构-教师模型设计 CourseOrg 课程信息 Teacher 教师信息 CityDict 城市信息 代码 from datetime import datetime from dj ...

  5. [py][mx]django实现课程机构排名

    如果是第一次做这个玩意,说实话,确实不知道怎么弄, 做一次后就有感觉了 此前我们已经完成了: 分类筛选 分页 这次我们做的是 课程机构排名 知识点: - 按照点击数从大到小排名, 取出前三名 hot_ ...

  6. [py][mx]django分页第三方模块django-pure-pagination

    前台的这些数据都是从后台取来的 分页模块django-pure-pagination - 一款基于django pagination封装的更好用的分页模块 https://github.com/jam ...

  7. [py][mx]django项目-让系统用自定义的users表认证

    项目开端 参考的是mxonline项目 先把这两项完成 1.app设计 2.app的models的设计 经过分析系统有四个模块 users - 用户管理 course - 课程管理 oranizati ...

  8. [py][mx]django处理登录逻辑

    浏览器同源策略(same-origin policy) csrf攻击防御核心点总结 django的cookie和session操作-7天免登录 flask操作cookie&django的see ...

  9. [py][mx]django自定义认证类-实现邮箱作为用户名登录

    创建自定义验证用户名密码类CustomBackend users/views.py from django.contrib.auth import authenticate, login from d ...

随机推荐

  1. 这款Office密码破解工具,无坚不摧!

    你是否曾经陷入过这样的尴尬:因为忘记Word文档密码去找了一个Word密码破解工具,接着又忘记Excel文档密码去找了一个专门破击Excel的工具,那么如果忘记PowerPoint.Outlook.P ...

  2. CString TCHAR互相转换

    CString->TCHAR*的转化可以用函数GetBuffer() // 原型:LPTSTR GetBuffer( int nMinBufLength ); CString str(_T(&q ...

  3. ios开发之--ZHPickView输出格式不出现 +0000

    这样写就不会输出 +0000了 NSDate *select = [_datePicker date]; NSDateFormatter *dateFormatter = [[NSDateFormat ...

  4. vs2008设置dll、lib库的输出路径

    vs2008中,有些项目上的功能是要生产库文件给其他项目调用的,以下是一些设置库文件(x.dll和x.lib)输出路径的方法. 设置x.dll 输出路径方法是在右键项目的"属性"- ...

  5. 详解Integer.toString(int i)方法和String.valueOf(int i)方法

    通过查看String类的源码: public static String valueOf(int i) { return Integer.toString(i); } 我们可以看到,String.va ...

  6. LeetCode——Add and Search Word - Data structure design

    Description: Design a data structure that supports the following two operations: void addWord(word) ...

  7. Ubuntu远程登录服务器--ssh的安装和配置

    ssh是一种安全协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全. 安装ssh sudo apt-get update sudo apt-get install openssh-serve ...

  8. 1296: [SCOI2009]粉刷匠[多重dp]

    1296: [SCOI2009]粉刷匠 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1919  Solved: 1099[Submit][Statu ...

  9. 安装Hadoop系列 — 安装SSH免密码登录

    配置ssh免密码登录   1) 验证是否安装ssh:ssh -version显示如下的话则成功安装了OpenSSH_6.2p2 Ubuntu-6ubuntu0.1, OpenSSL 1.0.1e 11 ...

  10. 【office2010】office2010安装问题的解决方案。

    今天想在公司电脑上按上一个office2010,结果出现一个问题,导致研究了一下午才解决:现总结解决方案: 安装office 2010,提示需要安装MSXML版本6.10.1129.0组件.但是在网上 ...