Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6611039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:55:08+00:00 2026-05-25T19:55:08+00:00

I want to retrieve the 13 latest objects, which shows this in my shell:

  • 0

I want to retrieve the 13 latest objects, which shows this in my shell:

>>> last_13_issues = Issue.objects.order_by('-id').order_by('-pub_date')[:13]
>>> print last_13_issues
[<Issue: X-Men v2 #18>, <Issue: Uncanny X-Men #543>, **<Issue: Herc #7>**, <Issue: X-Men: Schism #4>, <Issue: X-Men v2 #17>, <Issue: X-Men First Class: The High Hand #1>, <Issue: Astonishing X-Men #41>, <Issue: X-Men v2 #16>, <Issue: Generation Hope  #10>, <Issue: X-Men: Schism #3>, <Issue: Uncanny X-Men #542>, <Issue: X-Men: Schism #2>, <Issue: New Mutants v3 #28>]

Note Herc #7, which is marked with ** **.

In my template, I have a slider that shows the 3 latest objects, and then the rest of the objects not in a slider. So, I did this:

latest_appearances = Issue.objects.order_by('-id').order_by('-pub_date')[:3]
more_latest_appearances = Issue.objects.order_by('-id').order_by('-pub_date')[4:14]

latest_appearances shows this:

[<Issue: X-Men v2 #18>, <Issue: X-Men: Schism #4>, <Issue: Uncanny X-Men #543>]

more_latest_appearances shows this:

[<Issue: X-Men v2 #17>, <Issue: X-Men First Class: The High Hand #1>, <Issue: X-Men v2 #16>, <Issue: Astonishing X-Men #41>, <Issue: X-Men: Schism #3>, <Issue: Uncanny X-Men #542>, <Issue: Generation Hope  #10>, <Issue: X-Men: Schism #2>, <Issue: New Mutants v3 #28>, <Issue: Secret Avengers #15>]

Notice that Herc #7 is gone. Now, since I have it ordered by -pub_date, 4 of the issues in last_13_issues have the same pub_date, so what can I do to fix this? I have made sure that 3 issues show the same pub_date, but that’s obviously no help for when I have 4 issues with the same pub_date.

Ordering the issues only by id is no help either because sometimes I go back and add older issues, so sometimes issues with the highest id are not actually the latest issues.

Ok, odd. Case closed. I slice in the template, instead, and it works…which is weird that it doesn’t work in the views. But if anyone can figure out why, kudos to you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:55:08+00:00Added an answer on May 25, 2026 at 7:55 pm

    Use [3:] instead of [4:] for your more_latest_appearances.

    End index is non-inclusive for slicing:

    >>> "abcdef"[:3]
    'abc'
    >>> "abcdef"[4:]
    'ef'
    >>> "abcdef"[3:]
    'def'
    

    In order to clarify things more, I’d suggest rewriting your code a little to look like this:

    appearances = Issue.objects.order_by('-id').order_by('-pub_date')
    latest_appearances = appearances[:3]
    more_latest_appearances = appearances[3:14]
    

    This way, you only do a single query and then split the results up, rather than doing separate queries which might return the results in differing order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to retrieve all objects (not DOM elements) of a given type created
A user can have many addresses, but I want to retrieve the latest entry
I am using the latest Facebook Toolkit. I want to retrieve all albums of
I want to retrieve the latest object created for a particular user. Let's say
favorite Hello Everyone, I want retrieve daily latest NAV based on AMFI RSS Feeds
I want to retrieve a list of the files that has been added or
I want to retrieve a set of records from a database, do a rs.next()
I want to retrieve items from Fortress via its .NET API and load their
I want to retrieve stack trace from a user dump file programmatically . There
I want to retrieve a list of people's names from a queue and, for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.