几天前,我正在搞Django,试图感受一下东西是如何工作的,当我决定尝试构建一个简单的论坛时,它类似于一个论坛,我经常光顾(但现在关闭)。当时的想法是,每个评论的是父母任意数量的评论,就像这样:Django - 使用树建立一个评论系统
comment <--top
comment <-- comment "A"
comment <-- comment "B"
comment <-- comment "C"
comment <--C-1, reply to comment "C"
comment <-- C-1-1, reply to comment "C-1"
comment
comment
comment
comment <-- C-1-1-1 reply to C-1-1
comment
comment
comment
comment
comment
comment
comment
comment
comment
comment
comment
comment
这里的想法是,回复评论会酿下的每个评论一个级别,并且,除的第一个评论,有一位家长。事情是,虽然我得到了实现树遍历的想法,但是我没有读过关于这个主题的书/文章,并且考虑到了Django(或者MVC模式),所以我的问题是如何去做在Django中实现这个系统? (这里的型号代码,我已经有了一个参考: - /)
class Comment(models.Model):
Parent = models.OneToOneField('self', null=True)
Children = models.ForeignKey('self', null=True)
Author = models.ForeignKey(User)
Author_IP = models.IPAddressField()
Created_On = models.DateTimeField(auto_now_add=True)
Modified_On = models.DateTimeField(auto_now=True)
Body = models.TextField()
在档案中搜索,你可以找到很多答案。 http://stackoverflow.com/search?q=django+tree – 2009-12-22 16:27:45