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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:24:03+00:00 2026-06-01T10:24:03+00:00

I using Django tagging project. That is was very stable project. Working on django

  • 0

I using Django tagging project.

That is was very stable project.
Working on django 1.3.

But i have a problem.

# in models.py
from tagging.fields import TagField
class Blog(models.Model):
     title = models.CharField(max_length = 300)
     content = models.TextField()
     tags = TagField()
     author = models.ForeignKey(User)

# in views.py
def blog_list(request):
    # I Want to use select related with tags
    blogs = Blog.objects.all().select_related("user", "tags") # ????
    ....

# in Templates
{% load tagging_tags %}
{% for blog in blogs %}
    {% tags_for_object blog as tags %}
    {{blog.title}}
    {% for tag in tags %}
        <a href="{% url tag_detail tag_id=tag.pk %}">{{tag}}</a>
    {% endfor %}
{% 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-06-01T10:24:04+00:00Added an answer on June 1, 2026 at 10:24 am

    django-tagging uses a generic foreign key to your model, so you can’t just use select_related.

    Something like this should do the trick though:

    from django.contrib.contenttypes.models import ContentType
    from collections import defaultdict
    from tagging.models import TaggedItem
    
    def populate_tags_for_queryset(queryset):
        ctype = ContentType.objects.get_for_model(queryset.model)
        tagitems = TaggedItem.objects.filter(
            content_type=ctype,
            object_id__in=queryset.values_list('pk', flat=True),
        )
        tagitems = tagitems.select_related('tag')
        tags_map = defaultdict(list)
        for tagitem in tagitems:
            tags_map[tagitem.object_id].append(tagitem.tag)
        for obj in queryset:
            obj.cached_tags = tags_map[obj.pk]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using django-contact-form , I have overridden the form class: from contact_form.forms import ContactForm from
Using django 1.4 and have seen that when you use startproject it now creates
I am having problems using django-tagging . I try to follow the documentation but
Is it possible to have a variable number of fields using django forms? The
I have a fairly simple model that uses Django Taggit for tagging. Everything works
I'm using django-taggit. I am tagging action items and info items. I want to
Using Django 1.1, I am trying to select the maximum value from a varchar
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I just started using django for development. At the moment, I have the following
I'm using django, and have a static webpage with a GET form, and about

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.