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. MovieReview—NINE LIVES(九条命)

    Struggle & Family         A successful middle-aged man in the movie became a cat by falling from ...

  2. [大坑]Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

    报错tensorflow/stream_executor/cuda/cuda_dnn.cc:338] Could not create cudnn handle: CUDNN_STATUS_INTER ...

  3. gzip, gunzip, zcat - 压缩或展开文件

    总揽 gzip [ -acdfhlLnNrtvV19 ] [-S 后缀] [ 文件名 ... ] gunzip [ -acfhlLnNrtvV ] [-S 后缀] [ 文件名 ... ] zcat [ ...

  4. Xor Sum

    6498: Xor Sum 时间限制: 1 Sec  内存限制: 128 MB提交: 27  解决: 13[提交][状态][讨论版][命题人:admin] 题目描述 You are given a p ...

  5. 2018.5.6 解决问题:oracle------ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务

    解决问题:ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 或者是重启电脑之后无法进入控制台企业管理器(OEM)图形化界面(重新添加注入监听器就行了 文件listener.org) ...

  6. vue中文本域限制字数的方法

    用watch方法,来限制字数 <template> <div class="box"> <textarea v-model="title&q ...

  7. errno的用法

    Linux中系统调用的错误都存储于 errno中,errno由操作系统维护,存储就近发生的错误,即下一次的错误码会覆盖掉上一次的错误. 编程时需要包含#include <errno.h>, ...

  8. 【NOIP2017提高组模拟7.3】B

    树上路径统计,点分治解决. 统计一段区间,naive地用了set解决,这样的复杂度是O(nlog^2n)的 考场代码出了个问题,统计答案时找到了之前的最优答案,但是没有加上新的一段,导致60分 #in ...

  9. matlplotlib绘图(二)

    matplotlib基础知识 matpltlib中的基本图表包括的元素 1.x轴和y轴:水平和垂直的轴线 2.x轴和y轴的刻度:刻度标识坐标值的分隔,包括最小刻度和最大刻度 3.x轴和y轴刻度:表示特 ...

  10. tab key usage

    QA:gvim编辑ascii文本时由于tabkey的default setting 不合适编写Verilog代码(比如一个tab 代表多少空格) ANS: 1.tab 的自动补齐有两种usage自动补 ...