给Django1.5版本的QuerySet添加first()方法
来源:互联网 发布:公安备案阿里云服务器 编辑:程序博客网 时间:2024/05/19 20:20
这个方法1.6之后才有:https://docs.djangoproject.com/en/1.6/ref/models/querysets/
- first()
New in Django 1.6.
Returns the first object matched by the queryset, or None if there is no matching object. If the QuerySet has no ordering defined, then the queryset is automatically ordered by the primary key.
Example:
p = Article.objects.order_by('title', 'pub_date').first()
Note that first() is a convenience method, the following code sample is equivalent to the above example:
try: p = Article.objects.order_by('title', 'pub_date')[0]except IndexError: p = None
如何在1.5以及之前版本中使用这个方法呢?
解决如下:http://css.dzone.com/articles/adding-first-method-djangos
0 0
- 给Django1.5版本的QuerySet添加first()方法
- CodeBlocks中给工程添加版本信息的方法
- Django1.5版本运行时出现'url' requires a non-empty first argument. The syntax changed in Django 1.5, 的解决办法
- 基于 Django1.10 文档的深入学习(23)—— QuerySet API reference 之 icontains
- django1.4.1 最高支持的python 版本
- 关于Django1.6版本的Template设置
- Python3.5+Django1.8链接Mysql数据库的方法
- ios 给NSTimer添加Block回调版本创建方法
- ios 给NSTimer添加Block回调版本创建方法
- django1.6 博客的快速搭建first blog
- Django model,QuerySet 序列化成json的方法
- [Django1.5]'url' requires a non-empty first argument. 错误
- 给Repeater控件里添加序号的5种方法
- 给Repeater控件里添加序号的5种方法
- 给Repeater控件里添加序号的5种方法
- 给Repeater控件里添加序号的5种方法
- 给Repeater控件里添加序号的5种方法
- 给Repeater控件里添加序号的5种方法
- Android4.2蓝牙基础架构学习
- POJ 1228 (凸包)
- 游戏开发中UI提示诱惑特效
- java语言的科学与艺术 第五章 课后编程
- 迷你西游(手游)-邀请序列号
- 给Django1.5版本的QuerySet添加first()方法
- 数据结构,约瑟夫环非链表解...
- I2C总线学习记录
- linux下socket编程(1)tcp
- String&stringBuffer&包装类
- POJ 2007 (极角排序)
- 26、python 闹钟程序
- 一种不理解的写法
- 2014美图秀秀校招Android笔试题