[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 ...
随机推荐
- dedecms的arclist循环中判断第一个li添加css,否则不加
dedecms的arclist循环中,判断如果是第一个li,则添加固定的css,否则不加 写法如下: {dede:arclist row=4 flag='p'} <li [field:glo ...
- mongodb启动时报错ERROR: child process failed, exited with error number 1
不多说,直接上干货! 前期博客 Ubuntu14.04下Mongodb安装部署步骤(图文详解) Ubuntu16.04下Mongodb安装部署步骤(图文详解) root@zhouls-virtual- ...
- CentOS7.1 Liberty云平台之Dashboard篇(7)
控制节点: 一.安装及配置Dashboard 1.安装dashboard相关包 yum install openstack-dashboard 2.配置/etc/openstack-dashboard ...
- day23<File类递归练习>
File类递归练习(统计该文件夹大小) File类递归练习(删除该文件夹) File类递归练习(拷贝) File类递归练习(按层级打印) 递归练习(斐波那契数列) 递归练习(1000的阶乘所有零和尾部 ...
- python2.0_day16_django_url_view_models_template介绍
本节内容 Django流程介绍 Django url Django view Django models Django template Django form Django admin Django ...
- JVM学习(一)
JVM自身的物理结构:
- Linux 防火墙:Netfilter
一.Netfilter 简介 (1) Netfilter 是 Linux 内置的一种防火墙机制,我们一般也称之为数据包过滤机制,而 iptables 只是操作 netfilter 的一个命令行工具(2 ...
- Python 处理命令行参数
optparse模块用于从命令行直接读取参数,用法基本与 argparse模块 一致,如下: #!/usr/bin/env python #-*- coding:utf-8 -*- from optp ...
- MongoDB 用户角色
Read:允许用户读取指定数据库 readWrite:允许用户读写指定数据库 dbAdmin:允许用户在指定数据库中执行管理函数,如索引创建.删除,查看统计或访问system.profile user ...
- windows下配置nutch注意的问题
1.为处理方便,直接在$nutch目录下创建一个名为url.txt文件,然后在文件里添加要搜索的网址,例如:http://www.sina.com.cn/,注意网址最后的"/"一定 ...