ApathyBear
ApathyBear

Reputation: 9595

Querying all objects in order of creation except for the latest one

As the title explains, lets say I have the following queries:

    main_article = Article.objects.latest()
    prev_articles = Article.objects.all().order_by('-created')

I want the prev_articles to not include the latest article (the object that is main_article). I tried looking this up, but can't seem to find a way to exclude the latest one while chaining prev_articles.

How would you do it?

Upvotes: 0

Views: 35

Answers (1)

Hedde van der Heide
Hedde van der Heide

Reputation: 22449

try:
    articles = Article.objects.all().order_by('-created')[1:]
except IndexError:
    articles = Article.objects.none()

Upvotes: 2

Related Questions