'Attached' is how I have implemented grouping items.
Problem: it shows group headings when there are no items for that group.

And I don't like the fact that the inner loop spins through all the items for 
every outer loop.  doesn't scale well.

What I am used to is something like:

today_events = list of detail, order by eventtype.sequence, event.eventdate
eventtype=''
for event in today_events

   if event,eventtype !# eventtype
     # new group
     print event,eventtype.description
      eventtype=event,eventtype

   print event.title

What is a good way to implement this?

Carl K



# models.py
class EventType(models.Model):
     code=models.CharField(maxlength=10) # used in code, so don't change.
     description=models.CharField(maxlength=20)
     class Meta:
         ordering = ('sequence',)

class Event(models.Model):
     title = models.CharField(maxlength=47)
     eventdate = models.DateField()
     detail = models.TextField(blank=True)
     eventtype=models.ForeignKey(EventType, null=True)

# views.py
     event_types = EventType.objects.all()
     today_events = Event.objects.filter(
       show_on_main=True,
       eventdate = cur_day )

# welcome.html
     {% for event_type in event_types %}
         <h3>{{event_type.description }}</h3>
         {% for event in today_events %}
             {% ifequal event.eventtype event_type %}
    <li><a href="/eventcal/detail/{{ event.id }}/">{{ event.title }}</a> </li>
             {% endifequal %}
         {% endfor %}

     {% endfor %}



--~--~---------~--~----~------------~-------~--~----~
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