[英]why should we use parent in a Comment model?
what are self and parent?什么是自己和父母? this is part of a comment app
这是评论应用程序的一部分
models.py
模型.py
class Comment(models.Model):
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, blank=True, null=True)
email = models.EmailField(blank=True)
parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)
because a comment can be another comment's child, self
stands for class Comment
here.因为一个评论可以是另一个评论的孩子,
self
在这里代表class Comment
。
for example:例如:
father=Comment(user=...)
father.save()
son=Comment(user=...)
son.parent=father
son.save()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.