Friday, November 29, 2013

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

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>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b8366ac8-fd11-4426-a7e8-ab0c821ec1fc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment