I think I'm making this harder than it should be.  Could someone help
me out here please?  The gist is that I'm trying to display a list of
events like the following.  I'm getting the error "'offset' is not
allowed without 'limit'" which doesn't seem right.  I'm thinking
someone will spot a much simpler way to accomplish this that I'm not
seeing being new to Django.  Thanks in advance...

<h2>April</h2>
<b>April 10</b>
Event title<br>
Event body
<b>Event date</b>
Event title<br>
Event body
<h2>May</h2>
...


I have this events/models.py:

from django.db import models

class Event(models.Model):
    title = models.CharField(maxlength=200)
    body = models.TextField('Description')
    date_from = models.DateField('Starting date')
    date_to = models.DateField('Ending date', blank=True, null=True)

    class Admin:
        list_display = ('title','date_from')
        search_fields = ('title','body')
        date_hierarchy = 'date_from'

    def __str__(self):
        return self.title

    def longMonth(self):
        return self.date_from.strftime("%B")


This is my events/views.py:

from website.events.models import Event
from django.shortcuts import render_to_response

def index(request):
    return list(request)

def list(request):
    """
    Sets up a list of tuples: (month, list of events)
    [("March", [<event object>, <event object>]), ("April", [<>])]
    """
    evts = Event.objects.all().order_by('date_from')
    events_list = []

    prev_month = evts[0].longMonth()
    evlist = [evts[0]]
    evts = evts[1:]
    for e in evts:
      if prev_month == e.longMonth():
        evlist.append(e)
      else:
        events_list.append( (prev_month, evlist) )
        prev_month = e.longMonth()
        evlist = [e]

    return render_to_response('events/index.html', {'events_list':
events_list})


And my templates/events/index.html template:

{% extends "base.html" %}

{% block title %}Events{% endblock %}

{% block content %}
<h1>Events Calendar</h1>
{% if events_list %}
        {% for evtuple in events_list %}
                {% ifchanged %}<h2>{{ evtuple.0|date:"F" }}</h2>{%
endifchanged %}
                {% for e in evtuple.1 %}
                        <b>{{ e.date_from }}</b><br>
                        {{ e.title }}<br>
                        {{ e.body }}
                {% endfor %}
        {% endfor %}
{% endif %}
{% endblock %}


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to