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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:13:47+00:00 2026-05-23T02:13:47+00:00

I did template processor uses the backward following relationship. In the shell it works

  • 0

I did template processor uses the backward following relationship. In the shell it works OK, but in the view I have an error:

‘ParentCategory’ object has no attribute ‘postpages_set’

model (a little simpler than the original)

class ParentCategory(models.Model):
    category = models.CharField(max_length = 150)


class PostPages(models.Model):
    parent_category = models.ForeignKey('ParentCategory',
                                    blank = True,
                                    null = True,                                       
                                    related_name = "parent_category")
    title = models.CharField(max_length = 150)
    text = models.TextField()

context processor

from shivablog.shivaapp.models import ParentCategory

def menu_items(request):
    output_categories = {}
    category_list = ParentCategory.objects.all()
    for category in category_list:
        output_categories[category] = category.postpages_set.all()
    return {'output_categories': output_categories}

in the shell:

>>> output = {}
>>> cat_list = ParentCategory.objects.all()
>>> for cat in cat_list: 
...     output[cat] = cat.postpages_set.all()
... 
>>> output
{<ParentCategory: category#1>: [<PostPages: Post 1>, <PostPages: post 2>],         <ParentCategory: category #2>: [], <ParentCategory: category #3>: []}

What is going wrong? What the differece between shell and view in this way?

  • 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-23T02:13:47+00:00Added an answer on May 23, 2026 at 2:13 am

    You have explicitly renamed the related objects manager, using related_name, so it is now called parent_category:

    cat.parent_category.all()
    

    This is of course a very misleading name – I don’t know why you have set related_name at all.

    As for why it doesn’t appear in the shell, I can only assume you made the changes in the code without restarting your shell.

    Finally, however, I don’t know why you want to do this, as you can just as easily access the related objects in the template:

    {% for category in output_categories %}{{ category.parent_category.all }}{% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is what I did: 1. I have a template WORD file that can
My commandlink on menu.xhtml did not work. I have my menu.xhtml in template folder
I have posted a question earlier but unfortunately I did not get any useful
Did you ever have to choose between WISA or LAMP at the beginning of
Did you know that : Map<Object,Object> m1 = new HashMap<Object, Object>(); Map<Object,Object> m2 =
I found something related here but did not give me a good start Since
I have page for which I want to load different template file for different
I'm trying to render a template in a different language using i18n. I did
I want to write a sign function template. I did it like this: template<class
'WSGIRequest' object has no attribute 'username' This is the error I get . I

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.