How do you override a model's metaclass in Django 1.5? I was overriding the metaclass on some models inheriting from an abstract model so I could set appropriate choices. e.g.
class BaseModel(models.Model):
field_with_choices = models.CharField(max_length=100)
class Meta:
abstract = True
class MyModelMetaClass(BaseModel.__metaclass__):
def __new__(cls, *args, **kwargs):
new_class = super(MyModelMetaClass, cls).__new__(cls, *args, **kwargs)
field = new_class._meta.get_field('field_with_choices')
choices = field._choices = []
choices.extend(get_choices())
return new_class
class MyModel(BaseModel):
__metaclass__ = MyModelMetaClass
However, when I upgraded to Django 1.5, I now get the error:
AttributeError: type object 'BaseModel' has no attribute '__metaclass__'
How do you override a model's metaclass in 1.5, or otherwise dynamically set field attributes in model subclasses?