1π
The issue turned out to be unrelated to the actual admin class β The form used for add_form must be a subclass of ModelForm β in this case it was just a plain Form. When added to the page django introspects the form and attempts to inject a class in if itβs not a ModelForm, leading the to the metatype mismatch.
1π
This could happen if an incorrect metaclass is getting chosen for UserAdmin
, for example by __metaclass__
somehow getting inserted into the dict of the nascent class. Try the following test:
# force the correct metaclass:
metaclass = type(auth_admin.UserAdmin)
UserAdmin = metaclass("UserAdmin", (auth_admin.UserAdmin,), {})
If this works, it means a metaclass other than type(auth_admin.UserAdmin)
is getting picked in your class
statement. The culprit should be revealed by grepping Django sources and mixins for __metaclass__
.
If this fails with the same error, it could be that the metaclass constructor is doing some class construction of its own, which fails because of a genuine multiple inheritance error. In that case, a stack trace should reveal where this occurs.
- [Answered ]-How in Django upload Photo based on Gallery name from other model field?
- [Answered ]-Form action and its usage in Django
- [Answered ]-Errors not populated
- [Answered ]-Testing with Django: how to display all characters when using assertEqual with json object?
- [Answered ]-Regex to match combination of letter and numbers to be used in URL pattarns in Django Project?