添加mixin时,Django迁移没有检测到任何变化

时间:2015-02-26 19:38:46

标签: django

我正在尝试向现有模型添加CommentModelMixin,但运行makemigrations时django没有收到更改。相反,我得到no changes detected。如果我向同一模型添加字段,则会检测到更改并创建迁移文件。

django应该选择将mixin添加到makemigrations中的现有模型吗?

编辑:根据评论添加mixin

class CommentModel(FullModelMixin, FullManagerMixin):
    comment = models.TextField()
    thread = models.ForeignKey('ops.CommentModel', null=True)
    content_type = models.ForeignKey(ContentType)
    instance_pk = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'instance_pk')

    def __str__(self):
        if len(self.comment) > 10:
            return self.comment[:10] + '...'
        return self.comment

class CommentModelMixin(models.Model):

    comments = GenericRelation(
        CommentModel,
        object_id_field='instance_pk'
    )
    def add_comment(self, comment, thread=None):
        comm = ContentType.objects.get_for_model(self)
        CommentModel.objects.create(
            instance_pk=self.pk,
            content_type=comm, comment=comment, thread=thread
        )

    class Meta:
        abstract = True

0 个答案:

没有答案