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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:10:42+00:00 2026-06-09T02:10:42+00:00

I have a database with tags for an image gallery. They contain the fields

  • 0

I have a database with tags for an image gallery. They contain the fields ‘id’, ‘picture_id’ and ‘tag’. I am trying to build a list of all tags, but without listing the same tag twice. This I know I can do with distinct() in the queryset, but using this with all() only throws an error telling me that backend database does not support it. (I’m using MySQL).

If I use values_list(‘id’,’tag’) I don’t get that error. I don’t get any error at all actually. But I don’t get anything I can print out in my template either.

The queryset is written like this:

tags = Tag.objects.values_list('id', 'tag').distinct().order_by('tag')

In template I can try to print this with:

{% for tag in tags %}
    <p>{{ tag.id }}: {{ tag.tag }}</p>
{% endfor %}

This gives me a long(ish) row of ‘:’ signs, but nothing on its right or left side. This indicates to me that there are stuff in my list, but I can’t seem to use it. What am I doing wrong?

EDIT: It’s worth noting that I tried doing these things in a Shell and when printing out tags there I get a list of objects that seemingly consists of both id and tag, but I still can’t seem to get it output in template.

  • 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-09T02:10:43+00:00Added an answer on June 9, 2026 at 2:10 am

    values_list will create a list of tuples, not dictionaries, so using dictionary notation won’t work. Check out the the docs:

    … instead of returning a list of dictionaries, it returns a list of tuples. Each tuple contains the value from the respective field passed into the values_list() call — so the first item is the first field, etc. For example:

    >> Entry.objects.values_list('id', 'headline')
    [(1, u'First entry'), ...]
    

    So, instead you should do :

    {% for tag in tags %}
        <p>{{ tag.0 }}: {{ tag.1 }}</p>
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to display image from database using php but i am
I Have a old database to maintain .... they have stored html tags in
i have a database of links and tags. what is the easiest way i
i have a database table of website links. i have another table of tags,
I have a MySQL database with 3 tables: articles, tags, and articles_tags The schema
I have gallery in my project. I save images on the hard drive but
I have gallery.php that loads images with src path from a database. I also
I am using Sql database and a table has some fields that have data
Suppose I have a database which contains blog posts which have tags and I
I have a database populated with 1 million objects. Each object has a 'tags'

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.