我使用mongodb作为django nonrel数据库来构建一个博客站点。博客网站的基本模型是:
class Post:
comments = ListField(EmbeddedModelField('Comment'))
....(omitted here)
class Comment:
created = models.DateTimeField(auto_now_add=True)
author = models.CharField(max_length=35)
email = models.EmailField(max_length=64)
text = models.TextField()
ip_addr = models.IPAddressField()
我发现当我创建评论并将其附加到帖子的列表字段时,评论将不具有客观性,因为它是嵌入式的。因此,当我想删除评论时,我很难让数据库知道我要删除哪个评论。我是否有可能将注释从模板传递给urls.py中没有url函数的视图?
答案 0 :(得分:0)
您可以将模型重写为
class Post:
comments = ListField(models.ForeignKey('Comment'))
....(omitted here)
class Comment:
created = models.DateTimeField(auto_now_add=True)
author = models.CharField(max_length=35)
email = models.EmailField(max_length=64)
text = models.TextField()
ip_addr = models.IPAddressField()