from django.db import models
from django.utils import timezone
# Create your models here.
class Topic(models.Model):
    text = models.CharField(max_length=200)
    date_added = models.DateTimeField(auto_now_add=True)


    def __str__(self):

        return  self.text

class Entry(models.Model):

    topic = models.ForeignKey(Topic,on_delete=models.CASCADE)
    text = models.TextField()
    date_added = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name_plural = 'entries'

    def __str__(self):

        return self.text[:50] + "..."
#
class Ghomeentry(models.Model):
    title = models.CharField(max_length=200)
    content = models.CharField(max_length=500)
    userName = models.CharField(max_length=50)
    typeName = models.CharField(max_length=50)
    date_public = models.DateTimeField(auto_now_add=True)
    read_num = models.IntegerField()
    imageName = models.CharField(max_length=50)

    # def __str__(self):
    #
    #     return self

class Testentry(models.Model):
    title = models.CharField(max_length=200)
    content = models.CharField(max_length=500)
    userName = models.CharField(max_length=50)
    typeName = models.CharField(max_length=50)
    date_public = models.DateTimeField(auto_now_add=True)
    read_num = models.IntegerField()
    imageName = models.CharField(max_length=50)

    # def __str__(self):
    #
    #     return self

class Category(models.Model):
    """
    博客分类
    """
    name = models.CharField(verbose_name='博客类别', max_length=20)
    number = models.IntegerField(verbose_name='分类数目', default=1)

    class Meta:
        verbose_name = '博客类别'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Tag(models.Model):
    """
    博客标签
    """
    name = models.CharField(verbose_name='博客标签', max_length=20)
    number = models.IntegerField(verbose_name='标签数目', default=1)

    class Meta:
        verbose_name = '博客标签'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Blog(models.Model):
    """
    博客
    """
    title = models.CharField(verbose_name='标题', max_length=100)
    content = models.TextField(verbose_name='正文', default='')
    subContent = models.TextField(verbose_name='副文本')
    create_time = models.DateTimeField(verbose_name='创建时间', default=timezone.now)
    modify_time = models.DateTimeField(verbose_name='修改时间', auto_now=True)
    click_nums = models.IntegerField(verbose_name='点击量', default=0)
    category = models.ForeignKey(Category, verbose_name='博客类别',on_delete=models.CASCADE,)
    tag = models.ManyToManyField(Tag, verbose_name='博客标签')
    imageName = models.CharField(max_length=50)

    class Meta:
        verbose_name = '我的博客'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title

class Comment(models.Model):
    """
    博客评论
    """
    name = models.CharField(verbose_name='姓名', max_length=20, default='佚名')
    content = models.CharField(verbose_name='内容', max_length=300)
    create_time = models.DateTimeField(verbose_name='评论时间', auto_now_add=True)
    blog = models.ForeignKey(Blog, verbose_name='博客',on_delete=models.CASCADE,)

    class Meta:
        verbose_name = '博客评论'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content[:100]

class Counts(models.Model):
    """
    统计博客、分类和标签的数目
    """
    blog_nums = models.IntegerField(verbose_name='博客数目', default=0)
    category_nums = models.IntegerField(verbose_name='分类数目', default=0)
    tag_nums = models.IntegerField(verbose_name='标签数目', default=0)
    visit_nums = models.IntegerField(verbose_name='网站访问量', default=0)


    class Meta:
        verbose_name = '数目统计'
        verbose_name_plural = verbose_name

