I'm not sure the answers I'm sending from my email is working so I'm
reposting here on google groups.

In my case I wanted to get something like this:

<h2>January 2008</h2>
<ul>
    <li>Post name</li>
    <li>Post name</li>
</ul>
<h2>December 2007</h2>
<ul>
    <li>Post name</li>
    <li>Post name</li>
</ul>

I can't figure out how to do it the way your are saying. I thought
about doing:

    {% for entry in monts %}
    {% ifchanged %}<h2>{{ entry.pub_date|date:"F Y" }}</h2>{%
endifchanged %}
    <ul>
        <li>
            <a href="{{ entry.get_absolute_url }}" title="Read the
article titled {{ entry.title }}">{{ entry.title }}</a><span> on
{{ entry.pub_date|date:"l jS \o\f F Y" }}</span>
        </li>
    </ul>
    {% endfor %}

but that added <ul></ul> for every post like:

<ul><li>Post</li></ul>
<ul><li>Post</li></lu>

-Martin

On Feb 19, 8:54 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Wed, 2009-02-18 at 23:35 -0800, Marlun wrote:
> > I believe this will work perfectly in my case.
>
> > To easy my curiosity, how would you do it differently if you wanted
> > the sequence object to be grouped by date but have the month name
> > instead of number? I mean right now I get alistof entry objects. How
> > would you change your view code to retrieve a sequense sorted by month
> > name and year in the template?
>
> The month or year are more presentation details than data retrieval
> operations. You still sort the result set by date, which brings all 
> theentriesfor month X in a particular year together. Then, in your
> template, you can format the display however you like (including using
> the "ifchanged" template tag if you want to display some value only when
> it changes).
>
> Use the "date" template filter to format the results: if "obj" is a date
> object, the {{ obj|date:"M" }} will display the month name in a
> template.
>
> Regards,
> Malcolm
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to