在python中从对象引用类

时间:2019-04-14 18:17:16

标签: python django python-3.x django-models

我知道这可能很奇怪,但让我解释一下

class Comment(models.Model):
    profile = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name='comments')
    comment = models.TextField()
    target_ct = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    target_id = models.PositiveIntegerField()
    target = GenericForeignKey('target_ct', 'target_id')
    second_level_comment = GenericRelation(Comment, content_type_field='target_ct', object_id_field='target_id')

    def __str__(self):
        return self.comment[:40]

在上面的代码中,我有一个来自django的通用关系,我想引用评论中的评论
我可以使用过滤器使其正常工作 但我找不到解决方案,以将GenericRelation字段与对注释类本身的引用进行引用。 我想要类似self.__class__的东西,这里当然没有任何意义

0 个答案:

没有答案