Django notes III: Dynamic filtering
2024-10-15 19:46:37
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.
最新文章
- Kafka Linux 安装
- Eclipse中Ctrl+方法名发现无法进入到该方法中……
- 技术英文单词贴--V
- WebStorm mac 下载地址及注册码
- 21_resultMap和resultType总结
- hdu 1199 Color the Ball(离散化线段树)
- Case learning
- Spring(一)Spring的第一滴血
- 库函数strstr的实现
- BZOJ_3207_花神的嘲讽计划Ⅰ_哈希+主席树
- 如何在python脚本下启动django程序
- requests和session的区别
- SBT实操指南
- SQL优化思路大全
- flask小例
- 洛谷 P3749: LOJ 2146: [SHOI2017]寿司餐厅
- GPUImage简单滤镜使用(一)
- 【apache】phpstudy中apache 隐藏入口文件index.php (解决no input file specified错误)
- Android_读取元素的数据
- Java Swing实战(二)下拉菜单组件JComboBox及其事件监听