I'm modifying a third-party Django app based on django-mptt. I'm trying to refactor one monstrously big model into a base class and a set of mixins. All seemed well, however...
class ModelMixin([see below]):
class Meta:
abstract = True
class BaseModel(ModelMixin, MPTTModel):
class Meta:
abstract = False
- If
ModelMixin
inherits fromobject
, South doesn't see any fields declared in the mixin. - If
ModelMixin
inherits frommptt.models.MPTTModel
, the extra fields that django-mptt adds to MPTT-aware models get added twice; whichdjango-mptt
doesn't like, even though the mixin is abstract. - Most interestingly, if
ModelMixin
inherits fromdjango.db.models.Model
, I get this bloody weird error when I try to introduce a foreign key to that model:
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py"
line 900, in set_field_name
self.field_name = self.field_name or self.to._meta.pk.name
AttributeError: 'NoneType' object has no attribute 'name'