Does South handle model mixins?

谁说我不能喝 提交于 2019-12-22 09:07:04

问题


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:


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


来源:https://stackoverflow.com/questions/17343867/does-south-handle-model-mixins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!