BBS论坛 项目表分析

风格不统一 提交于 2020-01-11 02:02:47

 

一、项目表分析

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)

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!