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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:37:25+00:00 2026-05-25T10:37:25+00:00

Can’t seem to see where I am going wrong here. Forgive me because I

  • 0

Can’t seem to see where I am going wrong here. Forgive me because I am new to this. I am trying to display the 10 newest objects within a model.

Here is the loop I used to put all of these objects within a list:

 # put the top 10 newest Recipe objects in a list   
    entries_list = []
    all_recipes = Recipes.objects.annotate(Count('id'))
    newest_recipe_index = len(all_recipes)
    index = 0
    while index < 10:
        try:
            x = Recipes.objects.get(id=newest_recipe_index)
            entries_list.append(x)
            newest_recipe_index = newest_recipe_index - 1
            index = index + 1
        except:
            index = index + 1
            pass

I then render this to the page like so:

 c = RequestContext(request, {'form' : form, 'entries_list' : entries_list})
    return render_to_response("main.html", c)

And here is my html:

{% for entries in entries_list %}
        <i><b>Name:</i></b> {{ entries_list.name }}<br>
        <img src="/images{{ entries_list.picture }}" height="300" width="300"></img><br>
        <i><b>Ingredients:</i></b> {{ entries_list.ingredients }}<br>
        <p><i>{{ entries_list.description }}</i></p>
        <i><b>Created by:</i></b> {{ entries_list.user }}<br><br>
    {% endfor %}

And here is models.py:

class Recipes(models.Model):
    name = models.CharField(max_length=50)
    ingredients = models.CharField(max_length=300)
    picture = models.ImageField(upload_to = 'recipes/%Y/%m/%d')
    user = models.CharField(max_length=30)
    date = models.DateTimeField(auto_now=True)
    description = models.TextField()    
    comments = models.ManyToManyField(Comments)

It seems that the loop is working. The correct amount of entries are there. It is just that the template tags aren’t working. They are just blank. So it seems this is working just fine putting the objects inside the list, it just won’t retrieve my individual fields.

  • 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-25T10:37:26+00:00Added an answer on May 25, 2026 at 10:37 am

    A couple of things. There is a method by which you can order your query and just get the first ten entries. It would be more efficient than the loop you have.

    The reason your template doesn’t work is that you’re referring to the list rather than the individual entry. It should be:

    {% for entry in entries_list %}
            <i><b>Name:</i></b> {{ entry.name }}<br>
            <img src="/images{{ entry.picture }}" height="300" width="300"></img><br>
            <i><b>Ingredients:</i></b> {{ entry.ingredients }}<br>
            <p><i>{{ entry.description }}</i></p>
            <i><b>Created by:</i></b> {{ entry.user }}<br><br>
    {% endfor %}
    

    Once you get your template working, try this to get your entries_list:

    entries_list = Recipes.objects.order_by('-id')[0:10]
    

    Here’s the docs on sorting and slicing queries: https://docs.djangoproject.com/en/dev/topics/db/queries

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

Sidebar

Related Questions

Can anyone help me trying to find out why this doesn't work. The brushes
can anyone help me in trying to check whether JavaScript is enabled in client
can I make my own headers in HTTP request ? e.g. This is normal
Can this be done? It seems like this should be possible. In general, I
Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
Can I run this in a Windows command prompt like I can run it

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.