Q：Get latest “group” of objects in queryset

Q：获取最新的“组”对象的查询

I want to get a queryset containing the latest "group" of items (by date). Basically is there a prettier (and more efficent) way of doing this:

# get the latest set of news. It may or may not be today.
# TODO: this seems ugly, find a better way
latest = Article.objects.latest('published')
latest_items = Article.objects.filter(published__year=latest.published.year,
published__month=latest.published.month,
published__day=latest.published.day)

我想买一包含有最新的“组”的物品（日期）。基本上有一个漂亮的（更有效）的方式来做这件事：

# get the latest set of news. It may or may not be today.
# TODO: this seems ugly, find a better way
latest = Article.objects.latest('published')
latest_items = Article.objects.filter(published__year=latest.published.year,
published__month=latest.published.month,
published__day=latest.published.day)

answer1：

回答1：

The problem with your code is that it does some work twice and queries twice the db.

What you can do is query once with with select_related (to query only once the published data) and order_by: