Tim Chase wrote:
>> In my view, I have:
>> future_events = Event.objects.filter(start_date__gte=now)
>>     pacific_events = future_events.filter(club__region='Pacific')
>>     rocky_mountain_events = future_events.filter(club__region='Rocky
>> Mountain')
>>     southwest_events = future_events.filter(club__region='Southwest')
>>     midwest_events = future_events.filter(club__region='Midwest')
>>     central_events = future_events.filter(club__region='Central')
>>     northeast_events =
>> future_events.filter(club__region='Northeast')
>>     southeast_events =
>> future_events.filter(club__region='Southeast')
>>
>>     return render_to_response('clubs/events.html', {'
>>         'pacific_events': pacific_events,
>>         'rocky_mountain_events':rocky_mountain_events,
>>         'southwest_events':southwest_events,
>>         'midwest_events':midwest_events,
>>         'central_events':central_events,
>>         'northeast_events':northeast_events,
>>         'southeast_events':southeast_events,
>>     })
>>
>> And then in the view, I spit out:
>> {% if pacific_events %}
>>       do stuff
>> {% endif %}
>>
>> For each event type, ad nauseum.
> 
> Sounds like you want to do something like
> 
> future_events = Event.objects.filter(start_date__gte=now)
> regions = (
>      'Pacific',
>      'Midwest',
>      # ... or load from your Region table
>      )
> return render_to-response('clubs/events.html'), {'events': [
>          (region, future_events.filter(club__region=region)
>          for region in regions
>          ])
>      'other_context_field': whatever,
>      })
> 
> and then in your template, you'd have something like
> 
>    {% for region in events %}
>       <h3>Happenings in the {{ region.0 }} region</h3>
>       <ul>
>        {% for event in region.1 %}
>         <li>{{ event.description }}</li>
>        {% endfor %}
>       </ul>
>    {% endfor %}
> 
> Hope this helps,
> 
> -tim

tim,

I have a similar task, and this looks like what I need to do.

few minor questions:
missing )
[(region, future_events.filter(club__region=region) for region in regions]

guessing the missing ) goes here:
[(region, future_events.filter(club__region=region)) for region in regions]

What happens if there are no events in one of the regions?

Does that cause a hit to the DB for each region?

Carl K

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to