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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:50:52+00:00 2026-06-13T08:50:52+00:00

I’m using Django 1.4 with Python 2.7 on Ubuntu 12.04. I have a template

  • 0

I’m using Django 1.4 with Python 2.7 on Ubuntu 12.04.

I have a template that is supposed to show a product and a list of product features for each product and for some reason the features don’t show in the template.

Here is the view:

@login_required
def view_products(request):
    """
    ..  function:: view_products()

        View the Products

        :param request: Django Request object
    """

    data = { 'user' : request.user }
    if (request.user.is_authenticated() and request.user.is_superuser):
        products = Products.objects.all()

        add_feature_form = rsb.forms.AddProductFeatureForm();
        data.update({ 'form' : add_feature_form })
        data.update({ 'products' : products })
        data.update(csrf(request))

        return render_to_response("view_products.html", data)

    return render_to_response("index.html", data)

Here is the portion of the template working with the product features:

<table>
    {% for product in products %}
        <tr>
            <td align="right">Product Name:</td><td>{{ product.name }}</td>
        </tr>
        <tr>
            <td align="right">Price:<br /></td><td>${{ product.price }}</td>
        </tr>
        <tr>
            <ul>
            {% for productfeature in product.productfeature_set.all %}
                <form action="/removeProductFeature/" method="post">{% csrf_token %}
                <li>
                    {{ productfeature.feature }}
                    <input type="hidden" name="feature" value={{ productfeature.feature }}>
                    <input type="hidden" name="product_id" value={{ product.id }}>
                    <label class="formlabel">&nbsp;</label><input type="submit" value="Remove  &#9658;">
                </tr>
                </form>
            {% endfor %}
            </ul>
        </tr>
        <tr>
            <form action="/addProductFeature/" method="post">{% csrf_token %}
            <table>
                <tr>
                    <td align="right"><label class="formlabel">Add Feature:<br /></label></td><td>{{ form.feature }}</td>
                </tr>
                <input type="hidden" name="product_id" value={{ product.id }}>
                <tr>
                    <td align="right"><label class="formlabel">&nbsp;</label></td><td><input type="submit" value="Add  &#9658;"></td>
                </tr>
            </form>
            </table>
        </tr>
   {% endfor %}
</table>

Basically this template should show you a product. Each feature will be listed below it with the option to “remove” that feature. Then, at the bottom, a field that allows you to add additional features.

The existing features do not show up at all. Any suggestions on what I might be doing wrong?

UPDATE 1:

I missed an s in the template. product.productfeatures_set.all not product.productfeature_set.all. I’m good to go. Thanks all!

  • 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-13T08:50:53+00:00Added an answer on June 13, 2026 at 8:50 am

    Please don’t do this:

    product_features = []
    for product in products:
        features = ProductFeatures.objects.filter(product = product)
        product_features.append(features)
        product.features = product_features
    

    Instead, just pass your products variable to the template context.

    And in the template do:

    {% for product in products %}
        Product id: {{ product.pk }}
        {% for productfeature in product.productfeature_set.all %}
            {{ productfeature.feature }}
        {% endfor %}
    {% endfor %}
    

    What is productfeature_set you would ask (or, I hope you would ask :D), and that’s a very good question. Don’t panic, it’s all documented.

    Now, this is going to cause subqueries to spawn. The solution is to use prefetch_related. But you don’t have to worry about that for the moment I think 🙂

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.