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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:09:13+00:00 2026-05-17T18:09:13+00:00

Hey there, it’s been a week with Django back here so don’t mind me

  • 0

Hey there, it’s been a week with Django back here so don’t mind me if the question is stupid, though I searched over stackoverflow and google with no luck.

I’ve got a simple model called Term (trying to implement tags and categories for my news module) and I have a template tag called taxonomy_list which should output all the terms assigned to a post in a comma-separated list of links. Now, my Term model does not have a permalink field, but it gets there from within my view and is being passed on to the template. The permalink value looks fine inside the template, but doesn’t load up into my template tag.

To illustrate this I got bits from my code. Here’s my custom template tag called taxonomy_list:

from django import template
from juice.taxonomy.models import Term
from juice.news.models import Post

register = template.Library()

@register.tag
def taxonomy_list(parser, token):
    tag_name, terms = token.split_contents()
    return TaxonomyNode(terms)

class TaxonomyNode(template.Node):
    def __init__(self, terms):
        self.terms = template.Variable(terms)
    def render(self, context):
        terms = self.terms.resolve(context)
        links = []

        for term in terms.all():
            links.append('<a href="%s">%s</a>' % (term.permalink, term.name))

        return ", ".join(links)

Here’s my single post view:

# single post view
def single(request, post_slug):
    p = Post.objects.get(slug=post_slug)
    p.tags = p.terms.filter(taxonomy='tag')
    p.categories = p.terms.filter(taxonomy='category')

    # set the permalinks
    for c in p.categories:
        c.permalink = make_permalink(c)
    for t in p.tags:
        t.permalink = make_permalink(t)

    return render_to_response('news-single.html', {'post': p})

And this is what I do inside my template to illustrate two methods of accessing the categories:

Method1: {% taxonomy_list post.categories %}
Method2: {% for c in post.categories %}{{c.slug}} ({{c.permalink}}),{% endfor %}

What’s interesting is that Method number 2 works fine, but Method number 1 says that my .permalink field is undefined, this probably means that the variable resolution is not done as I’m expecting, since the “extra” permalink field is left out.

I thought that maybe the variable is not recognizing the field as it is not defined in the model so I tried assigning it a “temporary” value inside the model, but that didn’t help either. Method1 contained “temporary” in links, while method2 was working out correctly.

Any ideas?

Thanks!

  • 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-17T18:09:13+00:00Added an answer on May 17, 2026 at 6:09 pm

    It’s not really a question of variable resolution. The issue is how you’re getting the terms from the Post object.

    When, inside your template tag, you do for term in terms.all(), the all is telling Django to re-evaluate the queryset, which means querying the database again. So, your carefully-annotated terms are getting refreshed with new objects from the database, and the permalink attribute is getting overridden.

    It will probably work if you just drop the all – so you just have for term in terms:. This will re-use the existing objects.

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

Sidebar

Related Questions

Hey there, everyone. A really random question, but I'm looking to get into some
Hey there, I've got a block of HTML that I'm going to be using
Hey I was wondering if there were any way to upload images in ASP?
Hey, is there any built in functions or something like that in php that
Hey, in the Programming Pearls book, there is a source code for setting, clearing
Hey, I've been developing an application in the windows console with Java, and want
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey there, I'm trying to perform a backwards regular expression search on a string
Hey there I got a problem with my code, I compared three ways of
Hey there guys and gals. I'm very new to php and am following various

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.