Sunday, June 24, 2012

Re: Displaying events by month

Thank you Nikolas. Works perfect :)

On Wednesday, June 20, 2012 11:21:28 PM UTC+1, Nikolas Stevenson-Molnar wrote:
First, order by date in your query:

events = Event.objects.order_by('date')

Then in your template, use the ifchanged tag (https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#ifchanged):

{% for event in events %}
    {% ifchanged event.date.month event.date.year %}
        <h2>month here</h2>
    {% endifchanged %}
    <li>item here</li>
{% endfor %}

_Nik

On 6/20/2012 2:22 PM, grimmus wrote:
Hi,

I am trying to output upcoming events in the following format

June 2012
12th - Event 1
15th - Event 2

July 2012
1st - Event 3

August 2012
20th - Event 4

My model is very simple with just a title and dateTime field. I am unsure how i could output the months followed by the events in the style above. I guess nested loops would be necessary but would i need a separate loop for each month output ?

Thanks for any tips.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/RHAvjD4cKqUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/77AAh4wEiBkJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate