SELECT mii_events id mii_events author_id mii_events place_id mii_even

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
SELECT "mii_events"."id", "mii_events"."author_id", "mii_events"."place_id", "mii_events"."title", "mii_events"."date", "mii_events"."time", "mii_events"."description", "mii_events"."poster", "mii_events"."price", "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined", "mii_places"."id", "mii_places"."title", "mii_places"."image", "mii_places"."city_id", "mii_places"."address", "mii_places"."phone", "mii_places"."site", "mii_places"."exists", "mii_places"."description", "mii_places"."link_2gis", "mii_places"."lat", "mii_places"."lng", "mii_cities"."id", "mii_cities"."title" FROM "mii_events" INNER JOIN "auth_user" ON ("mii_events"."author_id" = "auth_user"."id") INNER JOIN "mii_places" ON ("mii_events"."place_id" = "mii_places"."id") INNER JOIN "mii_cities" ON ("mii_places"."city_id" = "mii_cities"."id") WHERE "mii_events"."date" >= E'2009-07-04'
SELECT "mii_groups"."id", "mii_groups"."city_id", "mii_groups"."genre_id", "mii_groups"."title", "mii_groups"."site", "mii_groups"."description" FROM "mii_groups" INNER JOIN "mii_events_groups" ON ("mii_groups"."id" = "mii_events_groups"."group_id") WHERE "mii_events_groups"."event_id" = 2
SELECT "mii_groups"."id", "mii_groups"."city_id", "mii_groups"."genre_id", "mii_groups"."title", "mii_groups"."site", "mii_groups"."description" FROM "mii_groups" INNER JOIN "mii_events_groups" ON ("mii_groups"."id" = "mii_events_groups"."group_id") WHERE "mii_events_groups"."event_id" = 2
======================================= django template =====================
{% load events_tags %}
{% get_events as events %}
{% for event in events %}
{% if event.groups.all %} {# Первый раз выбираются группы #}
{% for group in event.groups.all %} {# Второй раз выбираются группы #}
{{ group.title }}
{% endfor %}
{% endif %}
{% endfor %}