Help in pagination for DetailView with ListView inside

11 views
Skip to first unread message

lambi...@gmail.com

unread,
Aug 13, 2017, 8:51:18 AM8/13/17
to Django users
In the groups/views.py:
class SingleGroup(generic.DetailView):
    model
= Group

groups/urls.py:
    url(r'^posts/group/(?P<slug>[-\w]+)/$', views.SingleGroup.as_view(), name='single_group'),

groups/group_detail.html:
{% extends 'groups/group_base.html' %}
{% block pre-group %}
<div class="col-md-4">
   
<h1>{{ group.group_name }}</h1>
   
<h2>Members Count: {{ group.members.count }}</h2>
   
<div class="content">
       
{% if user in group.members.all %}
       
<a class="btn btn-warning" href="{% url 'groups:leave_group' slug=group.slug %}"><span class="glyphicon glyphicon-remove-circle"></span> Leave Group</a>
        {% else %}
 
       <a class="btn btn-warning" href="{% url 'groups:join_group'
slug=group.slug %}"><span class="glyphicon
glyphicon-ok-circle"></
span> Join Group</a>
        {% endif %}
    </
div>
</div>
{% endblock %}
{% block group_content %}
<div class="col-md-8">
    {% if group.post_counts.count == 0 %}
    <h2>No posts found</
h2>
   
{% else %}
   
{% for post in group.posts.all %}
   
{% include 'posts/_post.html' %}
   
{% endfor %}
   
{% endif %}
</div>
{% endblock %}

posts/_post.html:
<div class="post media">
   
<h3>{{ post.message_html|safe }}</h3>
   
<div class="media-body">
       
<strong>
            {{ post.user.username }}
       
</strong>
       
<h5 class="media-heading">
           
<span class="username"><a href="{% url 'posts:user_posts' username=post.user.username %}">@{{ post.user.username }}</a></span>
           
<time class="time"><a href="{% url 'posts:single_post' username=post.user.username pk=post.pk %}">{{ post.date_created }}</a></time>
            {% if post.group %}
           
<span class="group-name">in <a href="#">{{ post.group.group_name }}</a></span>
            {% endif %}
       
</h5>
       
<div class="media-footer">
            {% if user.is_authenticated and post.user == user and not hide_delete_button %}
           
<a href="{% url 'posts:delete_post' pk=post.pk %}" class="btn btn-danger">
               
<span class="glyphicon glyphicon-remove text-danger" aria-hidden="true"></span>
               
<span class="text-danger icon-label"></span> Delete
           
</a>
            {% endif %}
       
</div>
   
</div>
</div>

How do I use pagination in the DetailView? I only know to use it in ListView so far using the tutorials. I would gladly give more of the codes if the above are not helpful enough to solve the problem. Thank you in advance whoever can help!
Reply all
Reply to author
Forward
0 new messages