问题
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