1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| from django.db import models from django.contrib.auth.models import AbstractUser
class Userinfo(AbstractUser): '''用户表''' phone = models.BigIntegerField('手机号',null=True) avatar = models.FileField('头像', upload_to='avatar/', default='avatar/default.jpg') create_time = models.DateField('注册时间', auto_now_add=True) blog = models.OneToOneField(to='Site', null=True)
class Site(models.Model): '''个人站点''' site_title = models.CharField('站点标题', max_length=32) site_name = models.CharField('站点名称', max_length=32) site_theme = models.CharField('站点样式', max_length=32)
class Article(models.Model): '''文章表''' title = models.CharField('文章标题', max_length=32) desc = models.CharField('文章简介', max_length=32) content = models.TextField('文章内容') create_time = models.DateField('创建日期',auto_now_add=True)
comment_num = models.IntegerField('评论数', default=0) up_num = models.IntegerField('点赞数', default=0) down_num = models.IntegerField('点踩数', default=0)
blog = models.ForeignKey(to='Site', null=True) category = models.ForeignKey(to='Category', null=True) tag = models.ManyToManyField(to='Tag', through='ArticleToTag', through_fields=('article', 'tag'))
class Tag(models.Model): '''标签表''' name = models.CharField('文章标签', max_length=32) blog = models.ForeignKey(to='Site', null=True)
class ArticleToTag(models.Model): article = models.ForeignKey(to='Article') tag = models.ForeignKey(to='Tag')
class Category(models.Model): '''分类表''' name = models.CharField('文章分类', max_length=32) blog = models.ForeignKey(to='Site', null=True)
class UpAndDown(models.Model): '''点赞点踩''' user = models.ForeignKey(to='Userinfo') article = models.ForeignKey(to='Article') is_up = models.BooleanField('点赞点踩')
class Comment(models.Model): '''评论表''' user = models.ForeignKey(to='Userinfo') article = models.ForeignKey(to='Article') content = models.CharField('评论内容', max_length=255) comment_time = models.DateTimeField('评论日期',auto_now_add=True) parent = models.ForeignKey(to='self', null=True)
""" 1 1 写的真棒 2021 2 1 你放屁 2021 1 3 1 好好说话 2021 2 """
|