标签:abs one 主题样式 integer img create 站点 作者 一个
from django.db import models # Create your models here. from django.contrib.auth.models import AbstractUser,User class UserInfo(AbstractUser): nid=models.AutoField(primary_key=True) telephone=models.CharField(max_length=11,null=True,unique=True) avatar=models.FileField(upload_to=‘avatars/‘,default=‘/avatars/default.png‘)#用户头像 create_time=models.DateTimeField(verbose_name=‘创建时间‘,auto_now_add=True)#用户注册时间,生成表记录时自动添加 blog=models.OneToOneField(to=‘Blog‘,to_field=‘nid‘,null=True,unique=True) def __str__(self): return self.username class Blog(models.Model): nid=models.AutoField(primary_key=True) title=models.CharField(verbose_name="个人博客标题",max_length=64) site_name=models.CharField(verbose_name="站点名称",max_length=64) theme=models.CharField(verbose_name=‘博客主题样式‘,max_length=32) def __str__(self): return self.title #分类表 class Category(models.Model): nid = models.AutoField(primary_key=True) title=models.CharField(verbose_name="分类标题",max_length=32) blog=models.ForeignKey(verbose_name="所属博客",to="Blog",to_field="nid") def __str__(self): return self.title #标签表 class Tag(models.Model): nid=models.CharField(primary_key=True) title=models.CharField(verbose_name="标签名称",max_length=32) blog=models.ForeignKey(verbose_name=‘所属博客‘,to="Blog",to_field=‘nid‘) def __str__(self): return self.title #文章表 class Article(models.Model): nid = models.CharField(primary_key=True) title=models.CharField(verbose_name=‘文章标题‘,max_length=50) desc=models.CharField(verbose_name=‘文章描述‘,max_length=255) create_time=models.DateTimeField(verbose_name="文章创建时间",auto_now_add=True) content = models.TextField() # comment_count=models.IntegerField(default=0) # up_count=models.IntegerField(default=0) # down_count=models.IntegerField(default=0) user=models.ForeignKey(verbose_name=‘作者‘,to="UserInfo",to_field=‘nid‘) category=models.ForeignKey(verbose_name=‘文章分类‘,to=‘Category‘,to_field=‘nid‘,null=True) tags=models.ManyToManyField(to=‘Tag‘,through=‘Atricle2Tag‘,through_fields=(‘article‘,‘tag‘)) def __str__(self): return self.title class Atricle2Tag(models.Model): nid=models.AutoField(primary_key=True) article=models.ForeignKey(verbose_name=‘文章‘,to=‘Article‘,to_field=‘nid‘) tag=models.ForeignKey(verbose_name=‘标签‘,to=‘Tag‘,to_field=‘nid‘) class Meta: #联合唯一,也可以理解为联合主键 unique_together=[(‘article‘,‘tag‘),] def __str__(self): v=self.article.title+‘---‘+self.tag.title return v #点赞表 class ArticleUpDown(models.Model): nid=models.AutoField(primary_key=True) user=models.ForeignKey(to=‘UserInfo‘,to_field=‘nid‘,null=True) article=models.ForeignKey(to=‘Article‘,to_field=‘nid‘,null=True) is_up=models.BooleanField(default=True) class Meta: #联合唯一,一张表同一个用户只能点赞一次 unique_together=[(‘article‘,‘user‘),] #评论表 class Comment(models.Model): nid=models.AutoField(primary_key=True) article=models.ForeignKey(verbose_name="评论文章",to=‘Article‘,to_field=‘nid‘) user=models.ForeignKey(verbose_name="评论用户",to=‘UserInfo‘,to_field=‘nid‘) content=models.CharField(verbose_name="评论内容",max_length=255) create_time=models.DateTimeField(verbose_name=‘创建时间‘,auto_now_add=True) parent_comment=models.ForeignKey(to=‘Comment‘,to_field=‘nid‘,null=True) # parent_comment=models.ForeignKey(to=‘self‘,null=True) def __str__(self): return self.content
标签:abs one 主题样式 integer img create 站点 作者 一个
原文地址:https://www.cnblogs.com/yaya625202/p/9356968.html