35👍
✅
Abstract models still need to inherit from model.Model
to work correctly:
class TrackingFieldsMixin(models.Model):
Also instead of your active
BooleanField
I would add a deleted_on
DateTimeField
so you can record when the record was deleted. You can then just add properties on the instance to see if it’s active:
@property
def active(self):
return self.deleted_on is None
and in queries and/or a custom manager:
Blog.objects.filter(deleted_on__isnull=True)
Source:stackexchange.com