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