Reputation: 3
I have some database records for events on certain days and the people listed under the events but they are in two separate tables.
ex.
Events Table
Sport level Day
--------------------------------
Soccer Beginners Thursday
Handball Intermediate Thursday
Football Advanced Friday
Racquetball Novice Friday
Registration Table
Person event
-------------------------
Mike Jordan Soccer
Mark John football
Macry Smith Racquetball
James Reno Handball
What I want to do in a template is display this in a sort of schedule, I'm hoping to achieve something along the lines of:
Thursday
Beginners Soccer
Mike Jordan
Beginners Handball
James Reno
Friday
Advanced Football
Mark John
Novice Racquetball Macry Smith
How can I make this happen? I have gotten as far looping through the events table based on the day and can print the event but dont know how to make the people in those events follow immediately
View
Thurs_eve = object.Event.all(day = 'Thursday')
Fri_eve = object.Event.all(day = 'Friday')
template
<b>Thursday</b>
{% for Thurs in Thurs_eve %}
{{ Thurs }}
{% endfor %}
<b>Friday</b>
{% for Fri in Fri_eve %}
{{ Fri }}
{% endfor %}
Upvotes: 0
Views: 35
Reputation: 37876
I hope, the event
field in Register
model is a ForeignKey to/from Events
model.
in that case
<b>Friday</b>
{% for event in Fri_eve %}
{{ event.sport }}
{{ event.level }}
People:
{% for reg in event.registration_set.all %}
{{ reg.person }}
{% endfor %}
{% endfor %}
it will be then something like:
Football Advanced
People:
Mark John
Mike Jordan
..
btw: your ORM should be
Event.objects.filter(day = 'Friday')
Upvotes: 1