Django first () and last () Q query

Queryset return the first term and the last one, are used as follows:

p = Blog.objects.order_by('title').first()

Equivalent to:

try:
    p = Blog.objects.order_by('title')[0]
except IndexError:
    p = None

Guess you like

Origin www.cnblogs.com/hooo-1102/p/12078344.html