from django.db import models
from rbac.models import CommonModel
# Create your models here.

class Article(CommonModel):
    '''
    文章
    '''
    title = models.CharField(max_length=60, verbose_name='标题')
    elink = models.URLField(verbose_name='外部链接', null=True, blank=True)
    content = models.TextField(verbose_name='内容', blank=True)
    ifrom = models.CharField(max_length=60, verbose_name='来源')
    is_top = models.BooleanField('置顶', default=False)

    class Meta:
        verbose_name = '文章'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Material(CommonModel):
    """
    学习资料
    """
    type_choices = (
        ('文档', '文档'),
        ('视频', '视频'),
        ('图片', '图片'),
        ('音乐', '音乐'),
    )
    name = models.CharField(max_length=200, verbose_name='标题', unique=True)
    description = models.TextField('描述', null=True, blank=True)
    path = models.CharField(max_length=1000, verbose_name='文件地址')
    poster = models.CharField(max_length=10000, verbose_name='封面地址', null=True, blank=True)
    cate = models.CharField('分类', max_length=50, default='未分类')
    type = models.CharField('格式', default='文档', max_length=50)
    down_count = models.IntegerField('阅读量', default=0)
    sort = models.IntegerField('排序码', default=1)


class Source(CommonModel):
    name = models.CharField('来源名称', max_length=200)
    author = models.CharField('作者', max_length=100, null=True, blank=True)
    publish_year = models.PositiveSmallIntegerField('发表年份', null=True, blank=True)
    note = models.TextField('备注', null=True, blank=True)


class Threshold(CommonModel):
    source = models.ForeignKey(Source, verbose_name='来源', on_delete=models.CASCADE)
    compound_cate = models.CharField('化合物分类', max_length=10)
    odor_type = models.CharField('气味类型', null=True, blank=True, max_length=50)
    threshold_type = models.CharField('阈值类型', null=True, blank=True, max_length=50)
    toxicity_type = models.CharField('毒性类型', null=True, blank=True, max_length=50)
    chinese_name = models.CharField('中文名', max_length=50)
    ppm = models.FloatField('ppm值')
    ppm_sign = models.CharField('ppm符号标记', max_length=10, default='=')
    mass = models.FloatField('质量浓度')
    toxicity = models.FloatField('毒性', null=True, blank=True)
    mass_sign = models.CharField('质量浓度符号标记', max_length=10, default='=')
    molecular = models.FloatField('分子质量')
    cas = models.CharField('cas号', max_length=20)
    


    
