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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:36:45+00:00 2026-06-11T23:36:45+00:00

I learn Django ORM. class Toy(models.Model): name = models.CharField(max_length=20) desc = models.TextField() price =

  • 0

I learn Django ORM.

class Toy(models.Model):
    name = models.CharField(max_length=20)
    desc = models.TextField()
    price = models.DecimalField(max_digits=5, decimal_places=2)

class Box(models.Model):
    name = models.CharField(max_length=20)
    proprietor = models.ForeignKey(User, related_name='User_Box')
    toys = models.ManyToManyField(Toy, blank=True)

I try something like this in views:

def show_box(request):
    user = request.user
    box = Box.objects.filter(proprietor = user)

    return render_to_response('box.html', {'box': box})

in template:

{% for b in box %}
    Toy: {% for toys in b.toys.all %}{{ toys }}<br/>{% endfor %} 
    Price:
{% endfor %}

How to display the price of toys 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-11T23:36:46+00:00Added an answer on June 11, 2026 at 11:36 pm

    Just with the normal dot notation. toys is an instance of the Toy model so you can access the attributes on it:

    {% for box in boxes %}
        {% for toy in box.toys.all %}
            Toy: {{ toy.name }}<br/>
            Price: {{ toy.price }}<br/>
        {% endfor %}
    {% endfor %}
    

    Note that I’ve changed your variable names, which were confusing: the box variable that you passed to the template should really be boxes, as it’s a set of all the boxes owned by that proprietor, while toys inside the template should be toy, as it’s one specific toy from a box, not a set.

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

Sidebar

Related Questions

I am building an app to learn Django and have started with a Contact
Is not efficient :). I'm trying to learn django by building a simple app.
I'm starting to learn how to use Django on the Google App Engine. I
I want to learn and use Drupal or Django for the following: dynamic web
Trying to learn Django, I closed the shell and am getting this problem now
I decided to learn Django Forms. For a while now, I have been using
I am trying to learn Django (and Python) and have created my own app
I'm currently trying to learn Django from the book and I read most of
I'm looking for an excuse to learn Django for a new project that has
I am of the PHP background and just have started to learn Django and

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.