Add default value if a object does not have a entry with date in every month

6 views
Skip to first unread message

Tomas Jacobsen

unread,
Nov 29, 2013, 3:07:45 AM11/29/13
to django...@googlegroups.com
Hi

Im trying to make a table to show product prices over a year. 


Here is what Im doing on a YearArchiveView:


{% regroup object_list|dictsort:"store.id" by store as store_list %}
<ul>
    {% for store in store_list %}
    <li>{{ store.grouper }}
        
        
        {% regroup store.list|dictsort:"product" by product as product_list %}
        <ul>
            {% for product in product_list %}
                <li>{{ product.grouper }}
                    <ul>
                        {% for item in product.list|dictsort:"date" %}
                        <li>{{ item.price }} - {{ item.date|date }}</li>
                        {% endfor %}
                    </ul>
                </li>
            {% endfor %}
        </ul>
    </li>
    {% endfor %}
</ul>


This gives me this output:


<ul>

    <li>Apple
            <ul>
                
                    <li>iMac
                        <ul>
                            <li>395 - jun. 1, 2013</li>
                            <li>395 - jul. 1, 2013</li>
                            <li>395 - aug. 1, 2013</li>
                            <li>395 - sept. 1, 2013</li>
                            <li>395 - oct. 1, 2013</li>
                            <li>395 - nov. 1, 2013</li>
                        </ul>
                    </li>
            </ul>
        </li>
</ul>


Is it possible to display a default value if there is not a date entry in a month? Like this:

<ul>
    <li>Apple
            <ul>
                
                    <li>iMac
                        <ul>
                            <li>- jan. 1, 2013</li>
                            <li>- feb. 1, 2013</li>
                            <li>- mar. 1, 2013</li>
                            <li>- apr. 1, 2013</li>
                            <li>- may. 1, 2013</li>
                            <li>395 - jun. 1, 2013</li>
                            <li>395 - jul. 1, 2013</li>
                            <li>395 - aug. 1, 2013</li>
                            <li>395 - sept. 1, 2013</li>
                            <li>395 - oct. 1, 2013</li>
                            <li>395 - nov. 1, 2013</li>
                            <li>- des. 1, 2013</li>
                        </ul>
                    </li>
            </ul>
        </li>
</ul>
Reply all
Reply to author
Forward
0 new messages