from django.db import models from django.contrib.auth.models import AbstractUser # Create your models here. # 用户表 class UserInfo(AbstractUser): phone = models.BigIntegerField(null=True) create_time = models.DateField(auto_now_add=True) # 该字段会将接收的文件自动放到avatar文件夹下,只存放该文件的路径 avatar = models.FileField(upload_to='avatar') blog = models.OneToOneField(to='Blog', null=True) # 个人站点表 class Blog(models.Model): site_name = models.CharField(max_length=32) site_title = models.CharField(max_length=64) # 个人站点的样式文件,存放样式文件的路径 theme = models.CharField(max_length=64) # 分类表 class Category(models.Model): name = models.CharField(max_length=32) blog = models.ForeignKey(to='Blog', null=True) # 标签表 class Tag(models.Model): name = models.CharField(max_length=64) blog = models.ForeignKey(to='Blog', null=True) # 文章表 class Article(models.Model): title = models.CharField(max_length=64) desc = models.CharField(max_length=255) # 内容为大段文本内容 content = models.TextField() create_time = models.DateField(auto_now_add=True) # 查询优化 # 评论数 点赞数 点踩数 comment_num = models.IntegerField() up_num = models.IntegerField() down_num = models.IntegerField() blog = models.ForeignKey(to='Blog', null=True) category = models.ForeignKey(to='Category', null=True) tags = models.ManyToManyField(to='Tag', through='Article2Tags', through_fields=('article', 'tag')) class Article2Tags(models.Model): article = models.ForeignKey(to='Article') tag = models.ForeignKey(to='Tag') # 点踩点赞表 class UpAndDown(models.Model): user = models.ForeignKey(to='UserInfo') article = models.ForeignKey(to='Article') # 是点赞 1 还是点踩 0 is_up = models.BooleanField() # 评论表 class Comment(models.Model): user = models.ForeignKey(to='UserInfo') article = models.ForeignKey(to='Article') content = models.CharField(max_length=255) create_time = models.DateField(auto_now_add=True) parent = models.ForeignKey(to='self', null=True)
来源:https://www.cnblogs.com/xt12321/p/11061129.html