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

from ..models import Post

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

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

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