A small story about Django.
https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.first
It seems that first (and last) have been added to the queryset since about Django 1.6, and I now know that it can be conveniently used to take the first item ...
try:
p = Article.objects.order_by('title', 'pub_date')[0]
except IndexError:
p = None
p = Article.objects.order_by('title', 'pub_date').first()
Well convenient. It seems that Django 1.8 has also been released, so I have to check for new features.
Recommended Posts