Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def blog(request, tag_slug=None):
- newposts = post.objects.filter(status=True).order_by('created_date').reverse()[:3]
- tagscount = post.tags.most_common()[:6].annotate(post_count=Count('taggit_taggeditem_items'))
- categories = category.objects.all().annotate(post_count=Count('post'))
- posts = post.objects.filter(status=True).all().order_by('created_date').reverse()
- tag = None
- if tag_slug:
- tag = get_object_or_404(Tag, slug=tag_slug)
- posts = post.objects.filter(tags__in=[tag])
- paginator = Paginator(posts, 3)
- page = request.GET.get('page')
- try:
- postd = paginator.page(page)
- except PageNotAnInteger:
- postd = paginator.page(1)
- except EmptyPage:
- postd = paginator.page(paginator.num_pages)
- return render(request, 'site/bloggrid.html',
- {
- 'posts': posts,
- 'category': category,
- 'tag': tag,
- 'categories': categories,
- 'newposts': newposts,
- 'tagscount': tagscount,
- 'postd': postd,
- 'page': page,
- })
- {%if postd %}
- <div style="position: fixed;bottom:2em;left: 0;right:0;">
- <nav aria-label="...">
- <ul class="pagination justify-content-center">
- {% if postd.has_previous %}
- <li class="page-item">
- <a href="?page={{ postd.previous_page_number }}{% if request.GET.q %}&q=
- {{request.GET.q }}{% endif %}" class="page-link"><<</a>
- </li>
- {% endif %}
- {% for n in postd.paginator.page_range %}
- <li class="page-item {% if n == postd.number %}active{% else %}no-active{% endif %}">
- <a class="page-link" href="?page={{ n }}{% if request.GET.q %}&q={{ request.GET.q }}{% endif %}">{{ n }}</a>
- {% endfor %}
- {% if postd.has_next %}
- <li class="page-item">
- <a href="?page={{ postd.next_page_number }}{% if request.GET.q %}&q=
- {{ request.GET.q }}{% endif %}" class="page-link">>></a>
- </li>
- {% endif %}
- </ul>
- </nav>
- </div>
- {% endif %}
Add Comment
Please, Sign In to add comment