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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:08:24+00:00 2026-05-27T14:08:24+00:00

I have the models like this: Item: name desc AttrGroup: name order AttrName: name

  • 0

I have the models like this:

Item:
    name
    desc

AttrGroup:
    name
    order

AttrName:
    name
    group.ForeinKey(AttrGroup)
    order

AttrVal:
    value
    attr.ForeinKey(AttrName)
    item.ForeinKey(Item)

So I want to compare the attributes of n items in the list items_id=[1,3,7,…]

In views, I do something likes this:

attrs = AttrVal.object.filter(item__id__in=items_id)

and send to the templates. But I’m gonna confusing with the way how to arrange the list for interface.

The templates should like this:

<table>
    {% for g in group %}
        <tr class="group_name">{{ g.name }}</tr>
        {% for a in attrs %}
        <tr>
            <td>{{ a.name }}</td>
            {% for i in items_id %}
                <td>{{ value of item 'i' }}</td>
            { %endfor %}
        </tr>
        {% endfor %}
    {% endfor %}
</table>

I think it will have a good solution for this issue. Thanks!

Update:
Follow the pretty solution from @Lott, I found out the way how to show the data to templates. I’m using the code likes this:

{% for g in groups %}
    <tr class="title_row">
        <td class="group_name" colspan="{{ no_items }}">{{ g.0 }}</td>
    </tr>

    {% for a in g.1 %}
    <tr>
        <td>{{ a.attr.name }}</td>
        {% for i in comparing_items %}
            <td>{% if a.item.id == i %}{{ a.value }}{% endif %}</td>
        {% endfor %}
    </tr>
    {% endfor %}
{% endfor %}

And the it appears:

<table>
    <tr>
        <td>Attr Name 1</td>
        <td>Attr Value of Item 1</td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td>Attr Name 2</td>
        <td>Attr Value of Item 1</td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td>Attr Name 1</td>
        <td></td>
        <td></td>
        <td></td>
        <td>Attr Value of Item 4</td>
    </tr>
</table>

My goal is that list the same attribute of items [1,2,3,…] in a same row. The HTML should be like this:

<table>
    <tr>
        <td>Attr Name 1</td>
        <td>Attr Value of Item 1</td>
        <td>Attr Value of Item 2</td>
        <td>Attr Value of Item 3</td>
        <td>Attr Value of Item n</td>
    </tr>
    <tr>
        <td>Attr Name 2</td>
        <td>Attr Value of Item 1</td>
        <td>Attr Value of Item 2</td>
        <td>Attr Value of Item 3</td>
        <td>Attr Value of Item n</td>
    </tr>
    <tr>
        <td>Attr Name m</td>
        <td>Attr Value of Item 1</td>
        <td>Attr Value of Item 2</td>
        <td>Attr Value of Item 3</td>
        <td>Attr Value of Item n</td>
    </tr>
</table>

Thank you very much!

  • 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-27T14:08:25+00:00Added an answer on May 27, 2026 at 2:08 pm

    I used this for the problem:
    http://djangosnippets.org/search/?q=partition%20list

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

Sidebar

Related Questions

I have a simple model like this: class Auction(models.Model): name = models.CharField() class Item(models.Model):
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a model like this: class Item(models.Model): code = models.CharField(max_length=200, unique=True) barcode =
I have a model that looks like this: class Category(models.Model): name = models.CharField(max_length=60) class
I have this simplified model: class Item(models.Model): name = models.CharField(max_length=120) class ItemImage(models.Model): image =
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have two models like this: class OptionsAndFeatures(models.Model): options = models.TextField(blank=True, null=True) entertainment =

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.