views.py
def f_page(request, slug, f_slug):
f = get_object_or_404(F, slug= f_slug)
if f:
events = f.event_set.order_by('-pub_date')
if events:
for event in events:
comments = event.comment_set.order_by('-pub_date')
variables = RequestContext(request, {
'f' : f,
'events' : events,
'comments' : comments,
})
return render_to_response('f_page.html', variables)
Here events and comments are iterables. Each f has multiple events and then each event has multiple comments. The problem is how do I render this in my html page.I have tried this but it didn't work:
{% for event in events %}
<a href="/{{ event.author.username }}/">{{ event.author.first_name }}</a>
{{ event.pub_date }}
{{ event.description }}
{% for comment in comments %}
{{ comment }}
{{ comment.author.first_name }}
{% endfor %}
{% endfor %}
The events part shows up right but the comment set doesn't show up. My models work just fine I have tried everything in the admin panel. I can see where I'm messing it up but am unable to solve it. In 'views.py' the comments object for each event is not being saved. But, I don't know how to resolve it. Please help. Thanks in advance.