from django import template
from ..models import Post
from ..forms import SearchForm

from django.db.models import Count


register = template.Library()


@register.simple_tag
def total_posts():
    return Post.published.count()


# Tag to display the latest posts (default nimber of posts 5)
@register.inclusion_tag('blog/post/latest_posts.html')
def show_latest_posts(count=5):
    latest_posts = Post.published.order_by('-publish')[:count]
    return {'latest_posts': latest_posts}


# Tag to display the most commented posts
@register.simple_tag
def get_most_commented_posts(count=5):
    return Post.published.annotate(
        total_comments=Count('comments')).order_by('-total_comments')[:count]


# Tag to display the serch form
@register.inclusion_tag('search_form.html')
def show_search_form():
    search_form = SearchForm()
    return {'search_form': search_form}

30126431bc014950669f552b430c6626c6e32c9a
<mask token>


@register.simple_tag
def total_posts():
    return Post.published.count()


@register.inclusion_tag('blog/post/latest_posts.html')
def show_latest_posts(count=5):
    latest_posts = Post.published.order_by('-publish')[:count]
    return {'latest_posts': latest_posts}


<mask token>


@register.inclusion_tag('search_form.html')
def show_search_form():
    search_form = SearchForm()
    return {'search_form': search_form}

<mask token>


@register.simple_tag
def total_posts():
    return Post.published.count()


@register.inclusion_tag('blog/post/latest_posts.html')
def show_latest_posts(count=5):
    latest_posts = Post.published.order_by('-publish')[:count]
    return {'latest_posts': latest_posts}


@register.simple_tag
def get_most_commented_posts(count=5):
    return Post.published.annotate(total_comments=Count('comments')).order_by(
        '-total_comments')[:count]


@register.inclusion_tag('search_form.html')
def show_search_form():
    search_form = SearchForm()
    return {'search_form': search_form}

<mask token>
register = template.Library()


@register.simple_tag
def total_posts():
    return Post.published.count()


@register.inclusion_tag('blog/post/latest_posts.html')
def show_latest_posts(count=5):
    latest_posts = Post.published.order_by('-publish')[:count]
    return {'latest_posts': latest_posts}


@register.simple_tag
def get_most_commented_posts(count=5):
    return Post.published.annotate(total_comments=Count('comments')).order_by(
        '-total_comments')[:count]


@register.inclusion_tag('search_form.html')
def show_search_form():
    search_form = SearchForm()
    return {'search_form': search_form}

from django import template
from ..models import Post
from ..forms import SearchForm
from django.db.models import Count
register = template.Library()


@register.simple_tag
def total_posts():
    return Post.published.count()


@register.inclusion_tag('blog/post/latest_posts.html')
def show_latest_posts(count=5):
    latest_posts = Post.published.order_by('-publish')[:count]
    return {'latest_posts': latest_posts}


@register.simple_tag
def get_most_commented_posts(count=5):
    return Post.published.annotate(total_comments=Count('comments')).order_by(
        '-total_comments')[:count]


@register.inclusion_tag('search_form.html')
def show_search_form():
    search_form = SearchForm()
    return {'search_form': search_form}

from django import template
from ..models import Post
from ..forms import SearchForm

from django.db.models import Count


register = template.Library()


@register.simple_tag
def total_posts():
    return Post.published.count()


# Tag to display the latest posts (default nimber of posts 5)
@register.inclusion_tag('blog/post/latest_posts.html')
def show_latest_posts(count=5):
    latest_posts = Post.published.order_by('-publish')[:count]
    return {'latest_posts': latest_posts}


# Tag to display the most commented posts
@register.simple_tag
def get_most_commented_posts(count=5):
    return Post.published.annotate(
        total_comments=Count('comments')).order_by('-total_comments')[:count]


# Tag to display the serch form
@register.inclusion_tag('search_form.html')
def show_search_form():
    search_form = SearchForm()
    return {'search_form': search_form}
