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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:40:03+00:00 2026-05-27T22:40:03+00:00

i need to display some data from the DB. I need to display the

  • 0

i need to display some data from the DB.
I need to display the OrderItem and all related OrderProperties (with a FK)
In the view i do something like:

orderitems = OrderItem.objects.all().filter(order=order)
properties = []
for item in orderitems:
    a = OrderItemDetail.objects.all().filter(orderitem=item)
    b = []
    for x in a:
        c = [x.detail.property.name, x.detail.value, x.detail.price, x.detail.detail_price_unit]
    b.append(c)
 properties.append(b)

At the end I have a list of properties that i need then in the template I use them:

 # orderitems loop - displaying item detail
 # displaying the properties
 {% for prop in properties %}
     {% for x in prop %}
          <big><b>{{x.0}}</b>: {{x.1}} (+{{x.2}}
          {% if x.3 == "m" %}
          &euro;/MQ
          {% endif %}
          {% if x.3 == "p" %}
          %
          {% else %}
          &euro;
          {% endif %}
          )</big><br />
      {% endfor %}
 {% endfor %}

That should produce an output like: color: red (+0,0 € )
All works fine but when there are 2 or more orderitems i get each property printed in each record (I would like to display only the properties related to the current item)

It wold be quite easy if I could perform the query in the loop (retrieving only the properties that i need to display in that loop cycle). Yeah, I could create the html element in python, but since I’m using a template engine it seems pretty idiot.

Do you know any way to do that?

PS. i know variable names are meaningless but I need something short while testing

  • 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-27T22:40:04+00:00Added an answer on May 27, 2026 at 10:40 pm

    If I understand correctly, you need this.

    In view:

    orderitems = OrderItem.objects.all().filter(order=order)
    

    It template:

    {% for order in orderitems %}
       {% for detail in order.orderitemdetail_set.all %}
          {{ detail.property.name }}... etc
       {% endfor %}
    {% endfor%}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display some data(some text message) from a URL* (an HTML file)
Hi I need to create a module in drupal to display some data, not
I want to display some data which comes from my db using jQuery.ajax() (i.e.
I'm trying to use a DevExpress ASPxGridView to display some data. I need to
I need to display data from a database in a html table. I am
I'm developing a Web application. I need to display some decimal data correctly so
I have a master page that needs to display some data from my database.
I want to write an Android application that can display some data received(polled) from
I am trying to display some xml data from remote URL using jquery and
I am basically trying to retrieve some data from a MySql server, and display

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.