from django.contrib.auth.models import User
from django.db import models


class Category(models.Model):
	STATUS_NORMAL=1
	STATUS_DELETE=0
	STATUS_ITEMS=(
		(STATUS_NORMAL,'正常'),
		(STATUS_DELETE,'删除'),
	)
	
	name=models.CharField(max_length=50,verbose_name="名称")
	status=models.PositiveIntegerField(default=STATUS_NORMAL,
	choices=STATUS_ITEMS,verbose_name="状态")
	is_nav=models.BooleanField(default=False,verbose_name="是否为导航")
	owner=models.ForeignKey(User,verbose_name="作者",on_delete=models.CASCADE)
	created_time=models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
	
	class Meta:
		verbose_name=verbose_name_plural='分类'


class Tag(models.Model):
	STATUS_NORMAL=1
	STATUS_DELETE=0
	STATUS_ITEMS=(
		(STATUS_NORMAL,'正常'),
		(STATUS_DELETE,'删除'),
	)
	
	name=models.CharField(max_length=50,verbose_name="名称")
	status=models.PositiveIntegerField(default=STATUS_NORMAL,
	choices=STATUS_ITEMS,verbose_name="状态")
	owner=models.ForeignKey(User,verbose_name="作者",on_delete=models.CASCADE)
	created_time=models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
	
	class Meta:
		verbose_name=verbose_name_plural='标签'
		
class Post(models.Model):
	STATUS_NORMAL=1
	STATUS_DELETE=0
	STATUS_DRAFT=2
	STATUS_ITEMS=(
		(STATUS_NORMAL,'正常'),
		(STATUS_DELETE,'删除'),
		(STATUS_DRAFT,'草稿'),
	)
	
	title=models.CharField(max_length=255,verbose_name="标题")
	desc=models.CharField(max_length=1024,blank=True,verbose_name="摘要")
	content=models.TextField(verbose_name="body",help_text="正文必须为Markdown格式")
	status=models.PositiveIntegerField(default=STATUS_NORMAL,
	choices=STATUS_ITEMS,verbose_name="状态")
	category=models.ForeignKey(Category,verbose_name="分类",on_delete=models.CASCADE)
	tag=models.ManyToManyField(Tag,verbose_name="标签")
	owner=models.ForeignKey(User,verbose_name="作者",on_delete=models.CASCADE)
	created_time=models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
	pv=models.PositiveIntegerField(default=1)
	uv=models.PositiveIntegerField(default=1)
	
	class Meta:
		verbose_name=verbose_name_plural="文章"
		ordering=['-id']#根据id进行降序排列
		
	@staticmethod
	def get_by_tag(tag_id):
		try:
			tag=Tag.objects.get(id=tag_id)
		except Tag.DoesNotExist:
			tag=None
			post_list=[]
		else:
			post_list=tag.post_set.filter(status=Post.STATUS_NRMAL).select_related('owner','category')
		return post_list,tag
		
	@staticmethod
	def get_by_category(category_id):
		try:
			category=Category.objects.get(id=category_id)
		except Category.DoesNotExist:
			category=None
			post_list=[]
		else:
			post_list=category.post_set.filter(status=Post.STATUS_NORMAL).select_related('owner','category')
			
		return post_list,category
		
	@classmethod
	def latest_posts(cls):
		queryset=cls.objects.filter(status=cls.STATUS_NORMAL)
		
	@classmethod
	def get_navs(cls):
		categories=cls.objects.filter(status=cls.STATUS_NORMAL)
		nav_categories=[]
		normal_categories=[]
		for cate in categories:
			if cate.is_nav:
				nav_categories.append(cate)
			else:
				normal_categories.append(cate)
				
		return {
		'navs':nav_categories,
		'categories':normal_categories,
		}
		
	@classmethod
	def hot_posts(cls):
		return cls.objects.filter(status=cls.STATUS_NORMAL).order_by('-pv')
# Create your models here.

16c6f98441d6ad4270bc81bf15e952942e5b45d1
<mask token>


class Post(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_DRAFT = 2
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除'), (STATUS_DRAFT,
        '草稿')
    title = models.CharField(max_length=255, verbose_name='标题')
    desc = models.CharField(max_length=1024, blank=True, verbose_name='摘要')
    content = models.TextField(verbose_name='body', help_text='正文必须为Markdown格式'
        )
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    category = models.ForeignKey(Category, verbose_name='分类', on_delete=
        models.CASCADE)
    tag = models.ManyToManyField(Tag, verbose_name='标签')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    pv = models.PositiveIntegerField(default=1)
    uv = models.PositiveIntegerField(default=1)


    class Meta:
        verbose_name = verbose_name_plural = '文章'
        ordering = ['-id']

    @staticmethod
    def get_by_tag(tag_id):
        try:
            tag = Tag.objects.get(id=tag_id)
        except Tag.DoesNotExist:
            tag = None
            post_list = []
        else:
            post_list = tag.post_set.filter(status=Post.STATUS_NRMAL
                ).select_related('owner', 'category')
        return post_list, tag

    @staticmethod
    def get_by_category(category_id):
        try:
            category = Category.objects.get(id=category_id)
        except Category.DoesNotExist:
            category = None
            post_list = []
        else:
            post_list = category.post_set.filter(status=Post.STATUS_NORMAL
                ).select_related('owner', 'category')
        return post_list, category

    @classmethod
    def latest_posts(cls):
        queryset = cls.objects.filter(status=cls.STATUS_NORMAL)

    @classmethod
    def get_navs(cls):
        categories = cls.objects.filter(status=cls.STATUS_NORMAL)
        nav_categories = []
        normal_categories = []
        for cate in categories:
            if cate.is_nav:
                nav_categories.append(cate)
            else:
                normal_categories.append(cate)
        return {'navs': nav_categories, 'categories': normal_categories}

    @classmethod
    def hot_posts(cls):
        return cls.objects.filter(status=cls.STATUS_NORMAL).order_by('-pv')

<mask token>


class Category(models.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>


    class Meta:
        verbose_name = verbose_name_plural = '分类'


class Tag(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除')
    name = models.CharField(max_length=50, verbose_name='名称')
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')


    class Meta:
        verbose_name = verbose_name_plural = '标签'


class Post(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_DRAFT = 2
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除'), (STATUS_DRAFT,
        '草稿')
    title = models.CharField(max_length=255, verbose_name='标题')
    desc = models.CharField(max_length=1024, blank=True, verbose_name='摘要')
    content = models.TextField(verbose_name='body', help_text='正文必须为Markdown格式'
        )
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    category = models.ForeignKey(Category, verbose_name='分类', on_delete=
        models.CASCADE)
    tag = models.ManyToManyField(Tag, verbose_name='标签')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    pv = models.PositiveIntegerField(default=1)
    uv = models.PositiveIntegerField(default=1)


    class Meta:
        verbose_name = verbose_name_plural = '文章'
        ordering = ['-id']

    @staticmethod
    def get_by_tag(tag_id):
        try:
            tag = Tag.objects.get(id=tag_id)
        except Tag.DoesNotExist:
            tag = None
            post_list = []
        else:
            post_list = tag.post_set.filter(status=Post.STATUS_NRMAL
                ).select_related('owner', 'category')
        return post_list, tag

    @staticmethod
    def get_by_category(category_id):
        try:
            category = Category.objects.get(id=category_id)
        except Category.DoesNotExist:
            category = None
            post_list = []
        else:
            post_list = category.post_set.filter(status=Post.STATUS_NORMAL
                ).select_related('owner', 'category')
        return post_list, category

    @classmethod
    def latest_posts(cls):
        queryset = cls.objects.filter(status=cls.STATUS_NORMAL)

    @classmethod
    def get_navs(cls):
        categories = cls.objects.filter(status=cls.STATUS_NORMAL)
        nav_categories = []
        normal_categories = []
        for cate in categories:
            if cate.is_nav:
                nav_categories.append(cate)
            else:
                normal_categories.append(cate)
        return {'navs': nav_categories, 'categories': normal_categories}

    @classmethod
    def hot_posts(cls):
        return cls.objects.filter(status=cls.STATUS_NORMAL).order_by('-pv')

<mask token>


class Category(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除')
    name = models.CharField(max_length=50, verbose_name='名称')
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    is_nav = models.BooleanField(default=False, verbose_name='是否为导航')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')


    class Meta:
        verbose_name = verbose_name_plural = '分类'


class Tag(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除')
    name = models.CharField(max_length=50, verbose_name='名称')
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')


    class Meta:
        verbose_name = verbose_name_plural = '标签'


class Post(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_DRAFT = 2
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除'), (STATUS_DRAFT,
        '草稿')
    title = models.CharField(max_length=255, verbose_name='标题')
    desc = models.CharField(max_length=1024, blank=True, verbose_name='摘要')
    content = models.TextField(verbose_name='body', help_text='正文必须为Markdown格式'
        )
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    category = models.ForeignKey(Category, verbose_name='分类', on_delete=
        models.CASCADE)
    tag = models.ManyToManyField(Tag, verbose_name='标签')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    pv = models.PositiveIntegerField(default=1)
    uv = models.PositiveIntegerField(default=1)


    class Meta:
        verbose_name = verbose_name_plural = '文章'
        ordering = ['-id']

    @staticmethod
    def get_by_tag(tag_id):
        try:
            tag = Tag.objects.get(id=tag_id)
        except Tag.DoesNotExist:
            tag = None
            post_list = []
        else:
            post_list = tag.post_set.filter(status=Post.STATUS_NRMAL
                ).select_related('owner', 'category')
        return post_list, tag

    @staticmethod
    def get_by_category(category_id):
        try:
            category = Category.objects.get(id=category_id)
        except Category.DoesNotExist:
            category = None
            post_list = []
        else:
            post_list = category.post_set.filter(status=Post.STATUS_NORMAL
                ).select_related('owner', 'category')
        return post_list, category

    @classmethod
    def latest_posts(cls):
        queryset = cls.objects.filter(status=cls.STATUS_NORMAL)

    @classmethod
    def get_navs(cls):
        categories = cls.objects.filter(status=cls.STATUS_NORMAL)
        nav_categories = []
        normal_categories = []
        for cate in categories:
            if cate.is_nav:
                nav_categories.append(cate)
            else:
                normal_categories.append(cate)
        return {'navs': nav_categories, 'categories': normal_categories}

    @classmethod
    def hot_posts(cls):
        return cls.objects.filter(status=cls.STATUS_NORMAL).order_by('-pv')

from django.contrib.auth.models import User
from django.db import models


class Category(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除')
    name = models.CharField(max_length=50, verbose_name='名称')
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    is_nav = models.BooleanField(default=False, verbose_name='是否为导航')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')


    class Meta:
        verbose_name = verbose_name_plural = '分类'


class Tag(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除')
    name = models.CharField(max_length=50, verbose_name='名称')
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')


    class Meta:
        verbose_name = verbose_name_plural = '标签'


class Post(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 0
    STATUS_DRAFT = 2
    STATUS_ITEMS = (STATUS_NORMAL, '正常'), (STATUS_DELETE, '删除'), (STATUS_DRAFT,
        '草稿')
    title = models.CharField(max_length=255, verbose_name='标题')
    desc = models.CharField(max_length=1024, blank=True, verbose_name='摘要')
    content = models.TextField(verbose_name='body', help_text='正文必须为Markdown格式'
        )
    status = models.PositiveIntegerField(default=STATUS_NORMAL, choices=
        STATUS_ITEMS, verbose_name='状态')
    category = models.ForeignKey(Category, verbose_name='分类', on_delete=
        models.CASCADE)
    tag = models.ManyToManyField(Tag, verbose_name='标签')
    owner = models.ForeignKey(User, verbose_name='作者', on_delete=models.CASCADE
        )
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    pv = models.PositiveIntegerField(default=1)
    uv = models.PositiveIntegerField(default=1)


    class Meta:
        verbose_name = verbose_name_plural = '文章'
        ordering = ['-id']

    @staticmethod
    def get_by_tag(tag_id):
        try:
            tag = Tag.objects.get(id=tag_id)
        except Tag.DoesNotExist:
            tag = None
            post_list = []
        else:
            post_list = tag.post_set.filter(status=Post.STATUS_NRMAL
                ).select_related('owner', 'category')
        return post_list, tag

    @staticmethod
    def get_by_category(category_id):
        try:
            category = Category.objects.get(id=category_id)
        except Category.DoesNotExist:
            category = None
            post_list = []
        else:
            post_list = category.post_set.filter(status=Post.STATUS_NORMAL
                ).select_related('owner', 'category')
        return post_list, category

    @classmethod
    def latest_posts(cls):
        queryset = cls.objects.filter(status=cls.STATUS_NORMAL)

    @classmethod
    def get_navs(cls):
        categories = cls.objects.filter(status=cls.STATUS_NORMAL)
        nav_categories = []
        normal_categories = []
        for cate in categories:
            if cate.is_nav:
                nav_categories.append(cate)
            else:
                normal_categories.append(cate)
        return {'navs': nav_categories, 'categories': normal_categories}

    @classmethod
    def hot_posts(cls):
        return cls.objects.filter(status=cls.STATUS_NORMAL).order_by('-pv')

from django.contrib.auth.models import User
from django.db import models


class Category(models.Model):
	STATUS_NORMAL=1
	STATUS_DELETE=0
	STATUS_ITEMS=(
		(STATUS_NORMAL,'正常'),
		(STATUS_DELETE,'删除'),
	)
	
	name=models.CharField(max_length=50,verbose_name="名称")
	status=models.PositiveIntegerField(default=STATUS_NORMAL,
	choices=STATUS_ITEMS,verbose_name="状态")
	is_nav=models.BooleanField(default=False,verbose_name="是否为导航")
	owner=models.ForeignKey(User,verbose_name="作者",on_delete=models.CASCADE)
	created_time=models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
	
	class Meta:
		verbose_name=verbose_name_plural='分类'


class Tag(models.Model):
	STATUS_NORMAL=1
	STATUS_DELETE=0
	STATUS_ITEMS=(
		(STATUS_NORMAL,'正常'),
		(STATUS_DELETE,'删除'),
	)
	
	name=models.CharField(max_length=50,verbose_name="名称")
	status=models.PositiveIntegerField(default=STATUS_NORMAL,
	choices=STATUS_ITEMS,verbose_name="状态")
	owner=models.ForeignKey(User,verbose_name="作者",on_delete=models.CASCADE)
	created_time=models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
	
	class Meta:
		verbose_name=verbose_name_plural='标签'
		
class Post(models.Model):
	STATUS_NORMAL=1
	STATUS_DELETE=0
	STATUS_DRAFT=2
	STATUS_ITEMS=(
		(STATUS_NORMAL,'正常'),
		(STATUS_DELETE,'删除'),
		(STATUS_DRAFT,'草稿'),
	)
	
	title=models.CharField(max_length=255,verbose_name="标题")
	desc=models.CharField(max_length=1024,blank=True,verbose_name="摘要")
	content=models.TextField(verbose_name="body",help_text="正文必须为Markdown格式")
	status=models.PositiveIntegerField(default=STATUS_NORMAL,
	choices=STATUS_ITEMS,verbose_name="状态")
	category=models.ForeignKey(Category,verbose_name="分类",on_delete=models.CASCADE)
	tag=models.ManyToManyField(Tag,verbose_name="标签")
	owner=models.ForeignKey(User,verbose_name="作者",on_delete=models.CASCADE)
	created_time=models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
	pv=models.PositiveIntegerField(default=1)
	uv=models.PositiveIntegerField(default=1)
	
	class Meta:
		verbose_name=verbose_name_plural="文章"
		ordering=['-id']#根据id进行降序排列
		
	@staticmethod
	def get_by_tag(tag_id):
		try:
			tag=Tag.objects.get(id=tag_id)
		except Tag.DoesNotExist:
			tag=None
			post_list=[]
		else:
			post_list=tag.post_set.filter(status=Post.STATUS_NRMAL).select_related('owner','category')
		return post_list,tag
		
	@staticmethod
	def get_by_category(category_id):
		try:
			category=Category.objects.get(id=category_id)
		except Category.DoesNotExist:
			category=None
			post_list=[]
		else:
			post_list=category.post_set.filter(status=Post.STATUS_NORMAL).select_related('owner','category')
			
		return post_list,category
		
	@classmethod
	def latest_posts(cls):
		queryset=cls.objects.filter(status=cls.STATUS_NORMAL)
		
	@classmethod
	def get_navs(cls):
		categories=cls.objects.filter(status=cls.STATUS_NORMAL)
		nav_categories=[]
		normal_categories=[]
		for cate in categories:
			if cate.is_nav:
				nav_categories.append(cate)
			else:
				normal_categories.append(cate)
				
		return {
		'navs':nav_categories,
		'categories':normal_categories,
		}
		
	@classmethod
	def hot_posts(cls):
		return cls.objects.filter(status=cls.STATUS_NORMAL).order_by('-pv')
# Create your models here.
