views:

32

answers:

1

In my project I deal with various sorts of events taking places in different cities. I'd like to present list of events per city in a template, but how to do that ? My view now looks like this :

def events_by_state(request, state):
    cities = City.objects.filter(state_slug=state)

For each city I'd like do a query :

for c in cities:
    events_list = Event.objects.filter(city=c)

But then I have problem in what form and how should I send it, as well as use in my template ??

+2  A: 

Why would you do that? Just access the reverse attribute Django creates.

{% for city in cities %}
  {% for event in city.event_set.all %}
 ....
Ignacio Vazquez-Abrams
you mean city.event_set.all, right?
mawimawi
@mawimawi: Yes, of course.
Ignacio Vazquez-Abrams
I can use that in template ? damn I didn't know that. Works in 1.1 also ?
markus glock
@markus absolutely. (since 0.9x) or even earlier :)
mawimawi