EXTRACTED from the Django document
It's a common need to filter down the objects given in a list page by some key in the URL. Handily, the ListView has a get_queryset() method we can override. Previously, it has just been returning the value of the queryset attribute, but now we can add more logic.

The key part to making this work is that when class-based views are called, various useful things are stored on self; as well as the request (self.request) this includes the positional (self.args: a list) and name-based (self.kwargs: a dictionary) arguments captured according to the URLconf. You can use self.request.user to filter using the current user.

Django notes III: Dynamic filtering的更多相关文章

  1. django notes 七:Using Forms

    form 也没什么可说的,我只给一个例子大家就懂了 form model from django import forms class UserForm(forms.Form): username = ...

  2. django notes 六:数据库 CRUD 操作

    CRUD 也没什么可说的,django 提供了完善的 orm  api, 直接用就行了. 我只贴几个列子,一看就明白了,自己再用用就熟了. # create b = Blog(name='Beatle ...

  3. django notes 五:Writing models

    models 其实也没什么好说的,就是普通的 python 类 settings 中配置数据库连接 DATABASES = { 'default': { 'ENGINE': 'django.db.ba ...

  4. django notes 四: Writing views

    views 其实没什么可看的, 在  django  中 views 就是 controller, 是处理请求的, 就是一个普通的 python 方法. 一般从 request 中提取请求参数, 然后 ...

  5. django notes 三:Template 的查找

    django 中有 2种 Template Loader django.template.loaders.filesystem.Loader django.template.loaders.app_d ...

  6. django notes 二:URL dispatcher

    一般在 settings.py 中会有一个  ROOT_URLCONF ,请求到来时 django 会从 ROOT_URLCONF 指向的文件中查找  urlpatterns 变量配置的路由. url ...

  7. django notes 一:开篇

    公司 web 框架用的是 django, 以前没用过,打算这两周好好看看. 边学习边整理一下笔记,加深理解. 好像谁说过初学者更适合写入门级的教程,我觉得有一定道理. 高手写的教程有一定深度,不会写入 ...

  8. Django notes I: collection of links to the Django document

    Links to the Django documents: the Django template language automatically generated context variable ...

  9. Dynamic Filter Networks

    Dynamic Filter Networks 2019-06-10 11:29:19 Paper:http://papers.nips.cc/paper/6578-dynamic-filter-ne ...

随机推荐

  1. CCCC 以及 hihocoder offer收割赛11 ~~~

    CCCC  真的很蒙  ,没有队服,没有狗牌,服务器崩溃到14:10  才开始比赛...(黑人问号 开始前,发现旁边是西交老大吴航,mad~各种紧张.看着大佬疯狂的敲宏定义就很怕啊.100多行,一行头 ...

  2. 设置DataGridView控件中字体的样式

    实现效果: 知识运用: DataGridView控件的公共属性DefaultCellStyle的Font属性 public Font Font  {get;set;} //获取或设置应用与DataGr ...

  3. 01_12_JSP简介

    01_12_JSP简介 1. JSP简介 JSP---Java Server Pages 拥有servlet的特性与优点(本身就是一个servlet) 直接在HTML中内嵌JSP代码 JSP程序有JS ...

  4. 基础的Mapgis三维二次开发-插件式

    最近在做一个杭州石油的项目开发一个小系统. 1.命令必须是 ICommand 的派生类 using System; using System.Collections.Generic; using Sy ...

  5. Postman 没有走hosts文件

    问题: 在Windows10系统中,从官方下载Postman安装并登录后,创建一个请求并执行.但这个请求并没有走hosts文件中定义的192.168.33.10主机,而是走到了线上的主机. 分析: 通 ...

  6. 【Ubuntu】ubuntu基本操作命令

    本文主要是用于记录ubuntu中会使用到的命令,但是有不是特别常用的,用于自己后续查阅使用. 1.查询ubuntu版本信息 方法一: cat /etc/issue 方法二: sudo lsb_rele ...

  7. CentOS 6 搭建SVN支持httpd和svnserve独立服务器两种模式 以及邮件配置

    Linux下SVN服务器同时支持Apache的http和svnserve独立服务器两种模式且使用相同的访问权限账号 服务器操作系统:CentOS 6.x 1.在服务器上安装配置SVN服务: 2.配置S ...

  8. 能力不足之 根据时序图转化为Verilog代码

    不能够把时序图看的非常透彻,然后把时序图写成Verilog代码,有时候甚至搞不清楚信号之间的时序关系.

  9. 【linux】 服务器文件说明

    文件名 说明 /etc/resolv.conf  域名解析服务器地址文件 /etc/services 服务程序对应端口号文件 /etc/passwd 登录账号文件 /etc/hosts 本地IP域名解 ...

  10. java中类与对象的概念(2013-05-04-bd 写的日志迁移

    1:类是抽象的,概念的,代表一类事物,比如人类.猫类.. 2:对象是具体的,实际的,代表一个具体的事物 3:类是对象的模板,对象是类的一个个体,实例 创建对象的两种方法: 1.先声明在创建 对象声明: ...