python - Django - Exclude current post from side bar -


i playing django i'm having trouble templates. in post detail in including recent posts side bar template tag want exclude current post if is, in fact, 1 of recent. original hope use .exclude(id__post_detail=post) in blog_tag think might missing important concept, need request post_detail return response , can that? or perhaps define query in view , call blog_tag?

many in advance.

1.blog_tags.py

from django import template  register = template.library()  django.db import models django.utils import timezone ..models import post  @register.inclusion_tag('blog/sidebar.html') def sidebar_latest(request, count=5):          latest_posts= post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')[:count]     return {'latest_posts': latest_posts} 
  1. views

    def post_detail(request, pk):     post = get_object_or_404(post, pk=pk)     return render(request, 'blog/post_detail.html', {'post': post}) 
  2. post_detail

    {% extends 'blog/base.html' %} {% load blog_tags %} {% block content %} <div class="col-sm-12 col-md-9"> <div class="post"> <h1>{{ post.title }}</h1> {% if post.published_date %} <div class="date"> {{ post.published_date }} </div> {% endif %} <p>{{ post.text|linebreaksbr }}</p> </div> </div> <div class="col-sm-12 col-md-3"> {% sidebar_latest 3 %} </div> {% endblock %} 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -