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

  • Home
  • SEARCH
  • 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 3306130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:15:07+00:00 2026-05-17T21:15:07+00:00

I have the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model): title =

  • 0

I have the following models:

class Tag(models.Model):
  name = models.CharField(max_length=20)

class Entry(models.Model):
  title = models.CharField(max_length=100)
  date = models.DateField()
  tags = models.ManyToManyField(Tag)

In a view I create a list of Entry object and want to show the elements in the template:

   {% for entry in entries %}
     {{ entry.title }}
     {{ entry.date }}
   <!--  {% for tag in entry.tags %} {{ tag }} {% endfor %} -->
   {% endfor %}

And with this template code it generates the following TemplateSyntaxError pointing to the template’s first line (for tag):

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

The entries variable is a list:

entries = Entry.objects.filter(user=user_id)
entries = list(entries)
entries.sort(key=lambda x: x.id, reverse=False)

Do you know what can be the problem here and how to resolve this issue?

I’m new to Django, so any suggestions how to debug the templates may be helpful.

Update

I get the same error even with this template:

{% for entry in entries.all %}
<!-- everything is commented out here -->
{% endfor %}
  • 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-17T21:15:08+00:00Added an answer on May 17, 2026 at 9:15 pm

    There is no need to turn the entries QuerySet into a list. Additionally, you can let the DB do the sorting using order_by.

    entries = Entry.objects.filter(user_id=user_id).order_by('id')
    

    Add .all to get all the values from a relationship (just like Entry.objects.all()).

    entry.tags.all
    

    You can try this in the shell as well (I use ipython so your output may look different):

    $ ./manage.py shell
    # ...
    In [1]: from yourproject.models import Entry, Tags
    In [2]: entry = Entry.objects.all()[0]
    In [3]: entry.tags
    Out[3]: <django.db.models.fields.related.ManyRelatedManager object at 0x...>
    In [4]: entry.tags.all()  # for an entry with no tags.
    Out[4]: []
    In [5]: # add a few tags
    In [6]: for n in ('bodywork', 'happy', 'muscles'):
       ...:     t, created = Tag.objects.get_or_create(name=n)
       ...:     entry.tags.add(t)
    In [7]: entry.tags.all()
    Out[7]: [<Tag: ...>, <Tag: ...>, <Tag: ...>]
    

    And if you want to call out the entries with zero tags use for..empty.

    {% for tag in entry.tags.all %}
        {{ tag.name }}
    {% empty %}
        No tags!
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
Let's say I have the following model: class Contest: title = models.CharField( max_length =
i have the following models: class Tag(models.Model): tag_name = models.CharField(max_length=250) tagcat = models.ForeignKey('TagCat') class
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
Say I have the following in my models.py : class Company(models.Model): name = ...
I have the following models: class Post(models.Model): message = models.TextField() (etc.) class UserProfile(models.Model): user
Lets say, I have following models in my Django app. class EventGroup name =
I have the following models: class Keyword < ActiveRecord::Base has_many :tags has_many :studies, :through
I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name

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.