from user.models import Post,Category,Tag
from django import template
from django.db.models.aggregates import Count
register = template.Library()

# 最新文章模板标签
@register.simple_tag
def get_recent_posts(num=5):
    return Post.objects.all()[:num]

# 归档模板标签
@register.simple_tag
def archives():
    return Post.objects.dates('created_time','month',order='DESC')

# 分类模板标签
@register.simple_tag
def get_categories():
    return Category.objects.annotate(num_posts = Count('post')).filter(num_posts__gt = 0)

@register.simple_tag
def get_tags():
    return Tag.objects.annotate(num_posts=Count('post')).filter(num_posts__gt = 0)
a12bb68a0891ecaa2d1515ab36965e67961cb484
<mask token>


@register.simple_tag
def archives():
    return Post.objects.dates('created_time', 'month', order='DESC')


@register.simple_tag
def get_categories():
    return Category.objects.annotate(num_posts=Count('post')).filter(
        num_posts__gt=0)


@register.simple_tag
def get_tags():
    return Tag.objects.annotate(num_posts=Count('post')).filter(num_posts__gt=0
        )

<mask token>


@register.simple_tag
def get_recent_posts(num=5):
    return Post.objects.all()[:num]


@register.simple_tag
def archives():
    return Post.objects.dates('created_time', 'month', order='DESC')


@register.simple_tag
def get_categories():
    return Category.objects.annotate(num_posts=Count('post')).filter(
        num_posts__gt=0)


@register.simple_tag
def get_tags():
    return Tag.objects.annotate(num_posts=Count('post')).filter(num_posts__gt=0
        )

<mask token>
register = template.Library()


@register.simple_tag
def get_recent_posts(num=5):
    return Post.objects.all()[:num]


@register.simple_tag
def archives():
    return Post.objects.dates('created_time', 'month', order='DESC')


@register.simple_tag
def get_categories():
    return Category.objects.annotate(num_posts=Count('post')).filter(
        num_posts__gt=0)


@register.simple_tag
def get_tags():
    return Tag.objects.annotate(num_posts=Count('post')).filter(num_posts__gt=0
        )

from user.models import Post, Category, Tag
from django import template
from django.db.models.aggregates import Count
register = template.Library()


@register.simple_tag
def get_recent_posts(num=5):
    return Post.objects.all()[:num]


@register.simple_tag
def archives():
    return Post.objects.dates('created_time', 'month', order='DESC')


@register.simple_tag
def get_categories():
    return Category.objects.annotate(num_posts=Count('post')).filter(
        num_posts__gt=0)


@register.simple_tag
def get_tags():
    return Tag.objects.annotate(num_posts=Count('post')).filter(num_posts__gt=0
        )

from user.models import Post,Category,Tag
from django import template
from django.db.models.aggregates import Count
register = template.Library()

# 最新文章模板标签
@register.simple_tag
def get_recent_posts(num=5):
    return Post.objects.all()[:num]

# 归档模板标签
@register.simple_tag
def archives():
    return Post.objects.dates('created_time','month',order='DESC')

# 分类模板标签
@register.simple_tag
def get_categories():
    return Category.objects.annotate(num_posts = Count('post')).filter(num_posts__gt = 0)

@register.simple_tag
def get_tags():
    return Tag.objects.annotate(num_posts=Count('post')).filter(num_posts__gt = 0)