Django first()和last() Q查询
分别返回queryset的第一项与最后一项,具体用法如下:
p = Blog.objects.order_by(‘title‘).first()
等同于:
try: p = Blog.objects.order_by(‘title‘)[0] except IndexError: p = None
文章来自:https://www.cnblogs.com/hooo-1102/p/12078344.html
分别返回queryset的第一项与最后一项,具体用法如下:
p = Blog.objects.order_by(‘title‘).first()
等同于:
try: p = Blog.objects.order_by(‘title‘)[0] except IndexError: p = None