我目前有一堆旧评论,我需要迁移到django.contrib.comment
,计划是手动创建评论实例,然后按如下方式保存:
# assume some_content is NOT a django Comment instance, but in some proprietary format
# assume the model I'm attaching the comment to is called Blog i.e models.Blog
c = Comment()
c.user = user
c.submit_date = some_comment.comment_date_time
c.comment = some_comment.comment
...
c.save()
BaseCommentAbstractModel
主要问题是在类中发现的缺失信息django.contrib.comment.model
。具体三个字段:
BaseCommentAbstractModel(models.Model):
# Content-object field
content_type = models.ForeignKey(ContentType,
verbose_name=_('content type'),
related_name="content_type_set_for_%(class)s")
object_pk = models.TextField(_('object ID'))
content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_pk")
我阅读了文档,并尽我所能阅读了源代码,但还不够详细。如何从模型对象(model.Blog)中正确指定这些字段?
也许某处有一种方法可以接受模型对象和要添加的评论内容?