FieldTracker can't be inherited from abstract model#80
FieldTracker can't be inherited from abstract model#80rouge8 wants to merge 1 commit intojazzband:masterfrom
Conversation
|
Yeah, looking at Django's source for ModelBase, abstract models never call _prepare, which is where class_prepared is fired. Short of requiring the FieldTracker be on concrete models, I think it'd have to be changed upstream? |
|
Even if this is fixed upstream (I've filed https://code.djangoproject.com/ticket/21175), I think it would be possible to work around the lack of |
|
django-save-change implements some field-tracking mixins that override |
|
Until the upstream issue gets addressed, I created a workaround for this problem -- at least the case where the tracker is defined on the same class as the field. Haven't tested it on cases where the field and tracker are defined on separate parent classes, but since the magic happens in init, I don't see a reason for it not to work for those cases too. Won't say it's pretty (and it'll add some overhead on models that get instantiated frequently), but it seems to get the job done: https://gist.github.com/sbnoemi/7618916 If anyone has a more elegant workaround (alternative metaclasses?), I'd love to see it! |
We now just add stuff to the global_settings for defaults. Only install our Schema model if that is the settings.SCHEMA_MODEL Remove usage of FieldTracker/ModelTracker, they don't work with an abstract parent class anyway. See: https://code.djangoproject.com/ticket/21175 And: jazzband/django-model-utils#80 Also, start getting ready for django 1.7.
|
Using latest |
|
@bee-keeper it seems that you are right. @bee-keeper had you had a look at @sbnoemi proposal? Maybe handling this on AbstractModel is something model-util doesn't aim to provide? |
|
We are keeping track of the FieldTracker for AbstractModel in #382 I am closing this. |
I added a failing test case for inheriting a
FieldTrackerfrom an abstract model. It looks like theclass_preparedsignal isn't sent for abstract classes. :/