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 5983009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:10:07+00:00 2026-05-22T22:10:07+00:00

I am trying to show the 8 most recent scans added by doing this:

  • 0

I am trying to show the 8 most recent scans added by doing this:

def index(request):
....
recent_scans = Image.objects.filter(category='Scan').order_by('-date_added')[:8]
...

It “works,” but it is not literally getting the 8 most recent scans. The order is different compared to the order for the def scans. The order is not completely different, it’s just that there a few scans misplaced.

What is weird is that it works in this view:

def scans(request):
    image_list = Image.objects.filter(category='Scan').order_by('-date_added')

Taking out the [:8] to see if it’ll sort correctly does NOT work, though…so I don’t know what it wrong. My only guess is that the Image model is connected through a ManytoMany…

I’ve also tried this:

recent_scans = Image.objects.filter(category='Scan').latest('date_added')

But it comes with this error:

Caught TypeError while rendering: ‘Image’ object is not iterable

Here is my model, btw:

class Image(models.Model):
    CATEGORY_CHOICES = (
    ('Cover', 'Cover'),    
    ('Scan', 'Scan'),
    ('Other', 'Other'),
    )
    title = models.CharField(max_length=128)
    image = models.ImageField(upload_to="images/")
    category = models.CharField(max_length=10, choices=CATEGORY_CHOICES)
    contributor = models.ManyToManyField(Contributor, blank=True, null=True)
    date_added = models.DateField(auto_now_add=True)    
    def __unicode__(self):
        return self.title        
    class Meta:
        ordering = ['title']

I’ve tried adding ‘get_latest_by = “date_added”` to the Meta class in my models, but that did not work either.

  • 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-22T22:10:08+00:00Added an answer on May 22, 2026 at 10:10 pm

    I do not know why it doesn’t correctly order by date_added even though in my Issue model, it does. My only guess is that the database doesn’t correctly order by the latest item if it’s a DateField and not a DateTimeField. Weird, because, again, the Issue model does the same.

    So, I’ve simply just worked around it by sorting by the id and it works great!

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

Sidebar

Related Questions

n00b problem- I am trying to have a list show the most recent entry
I have solr query that simply returns the most recent items in the index.
This is the bane of my life: Traceback (most recent call last): File C:\Users\User\Documents\PYTHON\GAME
Trying to show a label only when a certain item in a combo is
I am trying to show by example that the prefix increment is more efficient
I'm trying to show updated results for a CCK Computed Field. The computation is
I'm trying to show thumbnail images in Django admin, but I can only see
I'm trying to show the number of times an operation occurred since the last
Ok I am trying to show a number using a series of Images. eg.
I am trying to show/hide a users twitter feed when the icon is clicked

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.