• BBS论坛项目


    一.表结构设计:

      1.帖子:

     1 class Article(models.Model):
     2     title = models.CharField(max_length=255,unique=True)
     3     category = models.ForeignKey('Category')
     4     priority = models.IntegerField(default=1000)
     5     author = models.ForeignKey("UserProfile")
     6     content = models.TextField(max_length=100000)
     7     breif = models.TextField(max_length=512,default='none.....')
     8     head_img = models.ImageField(upload_to="upload/bbs_summary/")
     9     publish_date = models.DateTimeField(auto_now_add=True)
    10  
    11     def __unicode__(self):
    12         return self.title

      2.评论:一对多。一个帖子有多个评论,一个评论针对一个帖子:

    1 class Comment(models.Model):
    2     bbs = models.ForeignKey('Article')
    3     parent_comment = models.ForeignKey('Comment',blank=True,null=True,related_name='p_comment')
    4     user = models.ForeignKey('UserProfile')
    5     comment = models.TextField(max_length=1024)
    6     date = models.DateTimeField(auto_now_add=True)
    7  
    8     def __str__(self):
    9         return self.comment

      3.:  

    1 class Thumb(models.Model):
    2     bbs = models.ForeignKey('Article')
    3     action_choices = (('thumb_up','Thumb Up'), ('view_count',"View Count"))
    4     action = models.CharField(choices=action_choices,max_length=32)
    5     user = models.ForeignKey('UserProfile')
    6  
    7     def __str__(self):
    8         return "%s : %s" %(self.bbs.title,self.action)

      4.板块(分类):

    1 class Category(models.Model):
    2     name = models.CharField(max_length=32,unique=True)
    3     enabled = models.BooleanField(default=True)
    4     def __str__(self):
    5         return self.name

      5.用户:

     1 class UserProfile(models.Model):
     2     user = models.OneToOneField(User)
     3     name = models.CharField(max_length=64)
     4     user_groups = models.ManyToManyField('UserGroup')
     5  
     6     friends = models.ManyToManyField("self",blank=True)
     7     online = models.BooleanField(default=False)
     8  
     9     def __str__(self):
    10         return self.name
  • 相关阅读:
    四种PHP异步执行的常用方式
    PHP 多进程和多线程的优缺点
    试着用workerman开发一个在线聊天应用
    Python代码报错看不懂?记住这20个报错提示单词轻松解决bug
    PHP面试题大全(值得收藏)
    常见排序算法(三)
    常见排序算法(二)
    常见排序算法(一)
    NumPy 学习笔记(四)
    JavaScript 事件
  • 原文地址:https://www.cnblogs.com/xussi/p/9822463.html
Copyright © 2020-2023  润新知