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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:44:13+00:00 2026-06-12T00:44:13+00:00

I have been searching for a way to make a django template which can

  • 0

I have been searching for a way to make a django template which can show more than 2 values per row in a table,

Let’s say I have an class with 5 attributes, and I want these attribute values presented in a table on my HTML page. at first I tried with a dictionary but just 2 of the 5 attributes is not enough.

Lets say my object is like:

class ModelA(models.Model):
    ID = models.IntegerField(primary_key=True, db_column='ID') 
    name = models.CharField(max_length=60, db_column='name')
    yesorno = models.CharField(max_length=9, db_column='yes/no') 
    text = models.TextField(db_column='text') 
    description = models.TextField(db_column='description') 

Now in a view I call for all these model attributes, in what datastructure should I save everything and how can I put all these 5 attributes in one row per object in a table.
(sometimes hundreds of objects may need to be shown in table (so, 100 rows))

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

    Grab all the objects (filter accordingly).

    As @init3 points out the ID is not required as Django adds that automatically, and yesorno should be a Bool.

    # view.py
    
    model_as = []
    for id in ids:
        try:
            model_a = ModelA.objects.get(ID=id)
        except ModelD.DoesNotExist:
            # No model found
            pass
        else:
            model_as.append(model_a)
    
    return render_to_response('template.html',
        {'model_as': model_as},
        context_instance=RequestContext(request))
    

    Loop over the objects in the template and print each variable in whichever column you want.

    # template.html
    <table>
    {% for model_a in model_as %}
        <tr>
            <td>
                {{ model_a.ID }}
                {{ model_a.name }}
                {{ model_a.yesorno }}
                {{ model_a.text }}
                {{ model_a.description }}
            </td>
        <tr>
    {% empty %}
        <tr>
            <td>No ModelAs to see here</td>
        <tr>
    {% endfor %}
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching for more than 1 hour with no success. Is there
I have been searching for a way to make a menu come 80 pixels
I have been searching a lot for a way to make a composite component
I have been searching for days for a way to always display just one
I have been searching several days for an example of how to make a
Good day, I have been searching for a way to format output using writeline/write
I've been searching for a way to make a textarea type inside of itself.
I have been searching for a few hours now on a way to fix
I've been unsuccessfully searching for a way to install make utility on my CentOS
Ok, I have been searching high and low for an easy way to implement

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.