Post.objects.all()
selected_post.event_post_set.all()
PostView
Post
EventView
post = Post.objects.get(pk=passed_in_post_pk)
...
return post.event_post_set.all()
.exists()
if
post_events_exist = post.event_post_set.all().exists()
if post_events_exist:
# there is at least 1 event in the query set.
# Rename EventView --> PostView
# Inside of your now PostView
# All we need to do is return all your instances of Post
# and go to your post_template.html (shows the posts, you call it events)
return Post.objects.all()
# Inside of a new view called EventView
# We can get to this view by clicking one of the posts above.
# This assumes we send a parameter through url in template.
# This will send user to event_template.html (shows all events for that post)
post = Post.objects.get(pk=passed_in_post_pk)
return post.post_event_set.all()
<!-- assuming all_posts = Post.objects.all() -->
{% for post in all_posts %}
{{ post.title }}
<a href="{{ url_that_links_to_event_view post.pk }}">Info</a>
<!-- this will send post.pk as a parameter to that view (so long as your accept a parameter in your urls.py for this link -->
{% endfor %}
{% for event in all_events %}
{{ event.price }}
{% endfor %}