Last active
August 29, 2015 14:27
-
-
Save varqasim/8c7df5c17635e60c3027 to your computer and use it in GitHub Desktop.
How a template would look like when using two models in a Django ListView http://stackoverflow.com/questions/12187751/django-pass-multiple-models-to-one-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for post in posts %} | |
<a href="{% url 'post' post_name_slug=post.slug %}"></a> | |
{% endfor %} | |
{% for post_comments in comments %} | |
{{ post_comments }} | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IndexView(ListView): | |
context_object_name = 'index' | |
queryset = Post.objects.all() | |
template_name = 'index.html' | |
def get_context_data(self, **kwargs): | |
context = super(IndexView, self).get_context_data(**kwargs) | |
context['posts'] = Post.objects.all() | |
context['comments'] = Comment.objects.all() | |
return context | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment