我创建了一个模型Comments
。我想在同一张桌子上回复Comment
。
class Comment(models.Model):
user = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
text = models.CharField(max_length=300, blank=False, null=False)
object_id = models.PositiveIntegerField()
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
content_object = GenericForeignKey('content_type', 'object_id')
# Relation
reply = GenericRelation(Comment, related_query_name='reply')
like = GenericRelation(Like, related_query_name='like')
我在这里收到此错误!
reply = GenericRelation(Comment, related_query_name='reply')
NameError: name 'Comment' is not defined
我该如何设置这种关系?