class CustomModelBase (ModelBase):
"""Metaclass for AbstractModel"""
def __new__ (cls, name, bases, attrs):
""" Sets SOME_ID to match the child model's name,
if it's not explicitly set in the child model"""
model = super (CustomModelBase,cls).__new__(cls, name, bases, attrs)
if not (model._meta.abstract or hasattr(model,'SOME_ID')):
setattr(model,'SOME_ID',model._meta.object_name)
return model
class AbstractModel(models.Model):
"""This is the abstract class to be inherited by model classes.
You define some common stuff here """
__metaclass__ = CustomModelBase
class Meta:
abstract = True
# objects = SomeCustomManager()
# custom_field = models.CharField (...)
# etc abstract attributes
class ActualDataModel (AbstractModel):
""" This is the actual model describing data.
It inherits all attributes from the AbstractModel class.
By default ActualModel.SOME_ID will be equal to "ActualModel".
However, you can override this by setting it explicitly:"""
# SOME_ID = 'SomeFunnyID'
Comments