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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:18:16+00:00 2026-06-08T00:18:16+00:00

I have a django template in which I wish to present a table of

  • 0

I have a django template in which I wish to present a table of fields. I want the table to contain different columns based on a subset of fields of a database. Which fields are displayed is based on a GET call (and thus cannot be predetermined).

The difficulty I am having is that I cannot label/order the columns arbitrarily and then get the fields to match up. I am using model.object.values to select the columns I want.

The solutions I have tried are:

  1. Iterating over the dictionary. This returns the fields in a random order, and furthermore in an order that is not guaranteed to be stable across elements of the database, although in practice this seems to be the case.
  2. Using values_list, however I still cannot control the order, but at least it’s fixed.
  3. Passing the field names, and using them to access the dictionary, however I cannot work out how to call dict.get with a parameter. I think this is intentionally impossible.
  4. Both 2 and 3 together. There is no obvious way to make this work without some ugly nested string comparisons and indexing hackery.
  5. Iterating over items, this seems to require nested loops to determine which element goes in which cell.

Any help would be appreciated.

N.B. dictsort sorts rows, not columns.

  • 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-08T00:18:18+00:00Added an answer on June 8, 2026 at 12:18 am

    You can either go with #3 and use the template filter suggested here or just prepare the data in your view instead of attempting to do this in your template. More specifically, you can create a list of column headings in your chosen order and for each object from your database create a tuple of values in the correct order.

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

Sidebar

Related Questions

I have a Django template that I want to extend in multiple places. In
I have a django template which extends the base template that has code to
I have a django template which loops over many notes/comments. As a simplified example
I have a django template which I have to send as email body, the
I have a django view which uses a template to display a long queryset
I've been searching around before asking this. I have Django template, which inputs a
I have a hidden field defined in my django template,value of which is passed
In one of my Django templates, I have a chunk of HTML which repeats
i have a django template - one that is normally loaded via a standard
I have a search field at the top of my django template (with no

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.