# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models


class Post(models.Model):
	status_ITEMS = (
    	(1, '上线'),
		(2, '草稿'),
		(3, '删除'),
	)
	title = models.CharField(max_length=50, verbose_name='标题')
	desc = models.CharField(max_length=255, blank=True, verbose_name='摘要')
	category = models.ForeignKey('Category', verbose_name='分类')
	tags = models.ManyToManyField('Tag', related_name="posts", verbose_name='标签')
	content = models.TextField(verbose_name='内容', help_text='注:目前仅支持Markdown格式')
	status = models.PositiveIntegerField(default=1, choices=status_ITEMS, verbose_name='状态')
	owner = models.ForeignKey(User, verbose_name='作者')
	created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
	lasted_update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
	
	def status_show(self):
		return '当前状态:%s'%(self.status)
	status_show.short_description = '展示站台' 
	def __unicode__(self):
		return self.title
	
	class Meta:
		verbose_name = verbose_name_plural = '文章'

    



class Category(models.Model):
	status_ITEMS = (
		(1, '可用'),
		(2, '删除'),

	)
	name = models.CharField(max_length=50,verbose_name='名称')
	status = models.PositiveIntegerField(default=1, choices=status_ITEMS, verbose_name='状态')
	owner = models.ForeignKey(User, verbose_name='作者')
	is_nav = models.BooleanField(default=False, verbose_name="是否为导航")
	created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
#    parent = models.ForeignKey('Category', verbose_name='分类')
	
	def __unicode__(self):
		return self.name
	   
	class Meta:
		verbose_name = verbose_name_plural = '分类'


class Tag(models.Model):
	status_ITEMS= (
		(1, '正常'),
		(2, '删除'),
	)

	name = models.CharField(max_length=50,verbose_name='名称')
	status = models.PositiveIntegerField(default=1, choices=status_ITEMS, verbose_name='状态')
	owner = models.ForeignKey(User, verbose_name='作者')
	created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
	
	def __unicode__(self):
		return self.name
	
	class Meta:
		verbose_name = verbose_name_plural = '标签'


