Hi, Jason,

On 11.05.2008, at 16:46, Jason K wrote:

>
> Hi, having a little trouble regrouping a date list.
> I have an simple inclusion tag to get a unique list of months, as
> follows:
>
> def show_month_list():
>    month_list = Article.objects.dates('pub_date', 'month',
> order='DESC')
>    return {'month_list': month_list}
> register.inclusion_tag('blog/_month_list.html')(show_month_list)
>
> ..and the template where I am trying to group them by year:
>
> <ul class="month_list">
>    {% regroup month_list by month_list|date:"Y" as grouped_list %}
month_list is a list and not a dictionary. AFAIK regroup only works  
with dicts.
I just did something similiar in my app.

    month_list = Article.objects.dates('pub_date', 'month',
order='DESC')

template_list = []
for d in month_list:
        template_list.append(
                {
                'group_by': d.strftime('%Y'),
                'date' : d
                }
        )

and in the template
<ul class="month_list">
    {% regroup template_list by group_by as grouped_list %}
    {% for group in grouped_list %}
        <li>year: {{ group.grouper }}
            <ul class="month_list">
                {% for item in group.list %}
                     <li>{{ item.date }}</li>
                {% endfor %}
            </ul>
        </li>
    {% endfor %}
</ul>


hope that helps.


adi

--
Adi J. Sieker         mobile: +49 - 178 - 88 5 88 13
Freelance developer   skype:  adijsieker
SAP-Consultant        web:    http://www.sieker.info/profile
                       openbc: https://www.openbc.com/hp/ 
AdiJoerg_Sieker/





--
Adi J. Sieker         mobile: +49 - 178 - 88 5 88 13
Freelance developer   skype:  adijsieker
SAP-Consultant        web:    http://www.sieker.info/profile
                       openbc: https://www.openbc.com/hp/ 
AdiJoerg_Sieker/




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to