Does South handle model mixins?

2019-05-07 06:24发布

I've created a mixin and inherited from it in some models. The problem is when I create a schema migration, the mixin's fields are there.

class MyMixin(object):
    a_field = models.CharField(max_length=30, blank=True)
    another_field = models.DateTimeField(blank=True, null=True)

    class Meta:
        abstract = True


class MyModel(models.Model, myMixin):
    ...

Any ideas?

1条回答
爷的心禁止访问
2楼-- · 2019-05-07 07:07

Seem to have got it working using the following

class MyMixin(models.Model):
    a_field = models.CharField(max_length=30, blank=True)
    another_field = models.DateTimeField(blank=True, null=True)

    class Meta:
        abstract = True


class MyModel(myMixin, models.Model):
    ...

The changes are:

  • MyMixin inherits Model rather than object (despite many discussions around the place saying that mixins for django should inherit object rather than Model)
  • the order of inheritance for MyModel - the mixin has to come first
查看更多
登录 后发表回答