Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can solve the problem with a template filter:</p> <ol> <li><p>Create a file for the filters (i.e. <code>&lt;YOUR_APP&gt;/templatetags/&lt;YOUR_FILTERS&gt;.py</code>) and add following code:</p> <pre><code>from django.template import Library from django.utils.datetime_safe import datetime register = Library() @register.filter def full_month_price_list(value): month_list = [[datetime(2013, i, 1)] for i in xrange(1, 13)] for item in value: month_list[item.date.month - 1].append(item) return month_list </code></pre> <p>This filter takes the list of items with a date attribute and returns a list with 12 lists of 2 elements: the date and the item</p></li> <li><p>In your template code load the filters (<code>{% load &lt;YOUR_FILTERS&gt; %}</code>) and change this:</p> <pre><code>&lt;ul&gt; {% for item in product.list|dictsort:"date" %} &lt;li&gt;{{ item.price }} - {{ item.date|date }}&lt;/li&gt; {% endfor %} &lt;/ul&gt; </code></pre> <p>by (<strong>UPDATED to format as table as you request in comments</strong>):</p> <pre><code>&lt;table&gt; {% for item in product.list|full_month_price_list %} &lt;tr&gt; &lt;td&gt;{{ item.0|date:"b. j, Y" }}&lt;/td&gt; &lt;td&gt;{{ item.1.price|default:"MISSING VALUE" }}&lt;/td&gt; &lt;/tr&gt; {% endfor %} &lt;/table&gt; </code></pre> <p>Note that you access to any property of the product <code>item.1.date</code>, <code>item.1.price</code>, <code>item.1.pk</code>, etc.</p></li> </ol> <p>Replacing <code>&lt;YOUR_APP&gt;</code> by the name of your django app, <code>&lt;YOUR_FILTERS&gt;</code> by the name you want to use for your filters file.</p> <p>Note that a file named <code>__init__.py</code> is needed in the directory <code>&lt;YOUR_APP&gt;/templatetags/</code>.</p> <p>More about custom filters in <a href="http://docs.djangoproject.com/en/1.6/howto/custom-template-tags/" rel="nofollow">django docs</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload