tags:

views:

28

answers:

1

Guys

I have the following view in my django application

def ViewSale( request ):
    salecur = Sale.objects.filter(user=2).order_by('sale_date')
    return render_to_response('myapp/sale.html',{'salecur':salecur})

my template looks like this

{% regroup salecur by sale_date as sale_list %}

<ul>
    {% for sale_date in sale_list %}
    <li>{{ sale_date.grouper }}
    <ul>
        {% for sale in sale_list %}
         <li>{{ sale.item }} - {{ sale.qty }} </li>
        {% endfor %}
    </ul>
    </li>
    {% endfor %}
</ul>

When i render the page i get the grouper sale_date.grouper printed, but {{ sale.item }} and {{ sale.qty }} in the inner loop shows nothing! Blank.

What am i missing?

Gath

+2  A: 
{% regroup salecur by sale_date as sale_list %}

<ul>
    {% for sale_date in sale_list %}
    <li>{{ sale_date.grouper }}
    <ul>
        {% for sale in sale_date.list %}
         <li>{{ sale.item }} - {{ sale.qty }} </li>
        {% endfor %}
    </ul>
    </li>
    {% endfor %}
</ul>

See the documentation on regroup:

{% regroup %} produces a list of group objects. Each group object has two attributes:

grouper -- the item that was grouped by (e.g., the string "Male" or "Female").
list -- a list of all items in this group (e.g., a list of all people with gender='Male').

Srikanth Chundi
+1 - thanks for figuring out what was wrong with my answer - I've edited in the relevant documentation from my answer and removed it.
Dominic Rodger
Still nothing is showing
gath
Anyone out there to assist me on this?
gath
Sorry, guess i was sleeping :( saw where i was goofing.
gath