[Answer]-Django __getitem__ on model: metaclass conflict

1๐Ÿ‘

โœ…

I would really suggest avoiding messing with the metaclass of models as you can easily run into some weird issues that are hard to debug. Anyway, if you still want to do this, the error message tells you what you need to do.

AlphaMeta needs to be a subclass of the metaclass of models.Model, which is django.db.models.base.ModelBase. So try

from django.db.models.base import ModelBase

class AlphaMeta(ModelBase):
    โ€ฆ

You probably also want to call the superclass implementation in the case of a KeyError.

๐Ÿ‘คMichael Mior

Leave a comment