标签:highlight self 作者 多对多 positive upload big text none
博客系统表关系整理; 1:创建用户信息表(UserInfo):-----------继承了AbstractUser(配置 settings: AUTH_USER_MODEL = "app01.UserInfo") ----------(from django.contrib.auth.models import AbstractUser) 主键(ID) 昵称(nickname) 电话(tel) 邮箱(email) 头像(avatar) 创建时间(create_time) 2:创建文章表(Acticle) 文章标题(title) 文章概要(summary) 创建时间(create_time) 修改时间(updata_time) 点赞数(poll_count) 评论数(comment_count) 阅读数(read_count) 作者(user)-------------------------------与信息表(Userinfo)是一对多的关系 所属类别(classify)-----------------------与分类表(Classify)是一对多的关系 标签(tag)--------------------------------与标签表(Tag)是多对多的关系,过滤关系,一篇文章只能有一层与标签的关系,不可重复。 博客的类,固定字段只有选择的权限(type_choices) 3文章详细表(Article_detail) 所属文章(article)------------------------与文章表是(Article)是一对一的关系 文章内容(content) 4标签表(Tag) 标签名(name) 所属博客(blog)----------------------------与博客表是一对多的关系 5博客和标签的关系表(Article2tag)--------------自己创建方便后面添加字段 文章(article)-----------------------------与文章表(Article)是多对一的关系 标签(tag)---------------------------------与标签表(Tag)是多对一的关系 6:评论表 评论时间(time) 评论内容(content) 评论人(user)------------------------------与用户信息表(UserInfo)是多对一的关系 评论文章(article)-------------------------与文章表(Acticle)是多对一的关系 父级评论(father_comment)------------------自关联(可以评论别人的评论) 7:文章点赞表(Article_poll) 点赞时间(time) 点赞文章(article)-------------------------与文章表(Acticle)是多对一的关系 点赞人(user)------------------------------与用户表(UserInfo)是多对一的关系 8:评论点赞表(Comment_poll) 点赞时间(time) 点赞用户(user)----------------------------与用户信息表(UserInfo)是多对一的关系 点赞所属评论(comment)---------------------与评论表(Comment)是多对一的关系 9:博客表(Blog) 个人博客标题(title) 路径(url) theme(博客主题) user(所属用户)----------------------------与用户信息表是(UserInfo)是一对一的关系 10:博主个人文章分类表(Classfication) 分类标题(title) 所属博客(blog)----------------------------与博客表是(Blog)是多对一的关系
from django.db import models from django.contrib.auth.models import AbstractUser class UserInfo(AbstractUser): #settings :AUTH_USER_MODEL ="项目名称.UserInfo" ‘‘‘用户信息表‘‘‘ nid = models.BigAutoField(primary_key=True) nickname =models.CharField(max_length=32,verbose_name="昵称",unique=True) tel = models.IntegerField(verbose_name="电话",unique=True,null=True,blank=True) email = models.CharField(max_length=64,verbose_name="邮箱") avatar = models.FileField(verbose_name="头像",upload_to="avatar",default="/avatar/default.png") create_time = models.DateTimeField(verbose_name="创建时间",auto_now_add=True) class Meta: verbose_name_plural = "用户信息表" def __str__(self): return self.username class Article(models.Model): ‘‘‘ 文章表 ‘‘‘ title = models.CharField(max_length=64,verbose_name="文章标题") summary = models.CharField(max_length=244, verbose_name="文章概要") create_time = models.DateTimeField(verbose_name="创建时间",auto_now_add=True) update_time = models.DateTimeField(verbose_name="修改时间",auto_now=True) poll_count = models.IntegerField(verbose_name="点赞数",default=0) comment_count = models.IntegerField(verbose_name="评论数",default=0) read_count = models.IntegerField(verbose_name="阅读数",default=0) # is_essence = models.BooleanField(verbose_name="是否精华",default=0) # is_top = models.BooleanField(verbose_name="是否置顶",default=0) user = models.ForeignKey(to="UserInfo",verbose_name="所属作者",null=True,blank=True) classify = models.ForeignKey(to="Classfication",verbose_name="所属类别",null=True,blank=True) tags = models.ManyToManyField(to="Tag",through="Article2tag",through_fields=(‘article‘, ‘tag‘),verbose_name="所属标签") type_choices = [ (1,"编程语言"), (2,"软件设计"), (3,"前端系列"), (4,"数据库"), (5,"操作系统") ] artcle_type_id = models.IntegerField(choices=type_choices,default=None) class Meta: verbose_name_plural = "文章表" def __str__(self): return self.title class Article_detail(models.Model): ‘‘‘文章细节表‘‘‘ article = models.OneToOneField(to="Article",verbose_name="所属文章") content =models.TextField(max_length=400,verbose_name="文章内容") class Meta: verbose_name_plural = "文章细节表" class Tag(models.Model): ‘‘‘标签表‘‘‘ name = models.CharField(max_length=32,verbose_name="标签名") blog = models.ForeignKey(to="Blog",verbose_name="所属博客") class Meta: verbose_name_plural = "标签表" class Article2tag(models.Model): article = models.ForeignKey(verbose_name="文章",to="Article") tag = models.ForeignKey(verbose_name="标签",to="Tag") class Meta: ‘‘‘联合唯一‘‘‘ unique_together = [ ("article","tag") ] class Comment(models.Model): ‘‘‘评论表‘‘‘ time = models.DateTimeField(verbose_name="评论时间",auto_now_add=True) content = models.CharField(max_length=265,verbose_name="评论内容") up_count = models.IntegerField(default=0) user = models.ForeignKey(to="UserInfo",verbose_name="评论人",null=True,blank=True) article = models.ForeignKey(to="Article",verbose_name="评论文章",null=True,blank=True) farther_comment = models.ForeignKey(to="Comment",verbose_name="父级评论",null=True,blank=True) # farther_comment = models.ForeignKey("self",verbose_name="父级评论",null=True,blank=True) class Meta: verbose_name_plural = "评论表" class Article_poll(models.Model): ‘‘‘文章点赞表‘‘‘ time = models.DateTimeField(verbose_name="点赞时间",auto_now_add=True) article = models.ForeignKey(to="Article",verbose_name="点赞文章",null=True,blank=True) #一个文章可以有多个赞 user = models.ForeignKey(to="UserInfo",verbose_name="点赞人",null=True,blank=True) # is_positive = models.BooleanField(default=1,verbose_name="点赞或踩") class Meta: ‘‘‘联合唯一‘‘‘ unique_together = ("user", "article",) verbose_name_plural = "文章点赞表" class Comment_poll(models.Model): ‘‘‘评论点赞表‘‘‘ time=models.DateTimeField(verbose_name="点赞时间",auto_now_add=True) # is_positive = models.BooleanField(verbose_name="点赞或踩",default=1) user = models.ForeignKey(to="UserInfo",verbose_name="点赞用户",null=True,blank=True) comment = models.ForeignKey(to="Comment",verbose_name="点赞所属评论",null=True,blank=True) #一个评论可以有多个赞 class Meta: ‘‘‘联合唯一‘‘‘ unique_together = ("user","comment",) verbose_name_plural = "评论点赞表" class Blog(models.Model): ‘‘‘个人站点表‘‘‘ title = models.CharField(max_length=32,verbose_name="个人博客标题") url = models.CharField(max_length=64,verbose_name="路径",unique=True) theme = models.CharField(max_length=32,verbose_name="博客主题") user = models.OneToOneField(to="UserInfo", verbose_name="所属用户") class Meta: ‘‘‘通过admin录入数据的时候个中文显示‘‘‘ verbose_name_plural = "个人站点表" def __str__(self): return self.title class Classfication(models.Model): ‘‘‘博主个人文章分类表‘‘‘ title = models.CharField(max_length=32, verbose_name="分类标题") blog = models.ForeignKey(to="Blog",verbose_name="所属博客") class Meta: verbose_name_plural = "分类表"
标签:highlight self 作者 多对多 positive upload big text none
原文地址:http://www.cnblogs.com/w-s-l123/p/7858197.html