I'm following a tutorial for the Django admin app and I'm trying a step in which the default admin site is replaced with a custom subclass of AdminSite from django.contrib.admin.
My project structure is:
MyAdminTutorial
|- MyAdminTutorial
|- MyActualApp
|- JustAUserApp
MyActualApp.admin.py:
[...other imports]
from django.contrib.auth.admin import UserAdmin, GroupAdmin
class MyAdminSite(admin.AdminSite):
pass
admin.site = MyAdminSite()
admin.site.register(User, UserAdmin)
admin.site.register(Group, GroupAdmin)
MyActualApp.apps.py:
from django.contrib.admin.apps import AdminConfig
class MyAdminConfig(AdminConfig):
default_site = 'MyActualApp.admin.MyAdminSite'
MyAdminTutorial.settings.py
INSTALLED_APPS = [
"MyActualApp.apps.MyAdminConfig",
# 'django.contrib.admin',
....
"JustAUserApp",
]
If I try to run the development server I get this error:
ImportError: Module "MyActualApp.admin" does not define a "MyAdminSite" attribute/class
Messing around in the debugger i found the error stems from a call to getattr() inside import_string() in django.utils.module_loading.py.
For the current call to import_string() the module name and path are set to MyActualApp.admin, getting the current location in the debug console yields the main MyActualApp directory (the project's), but calling getattr(module, "MyAdminSite") triggers the error above.
I expect the MyAdminSite class to be found, but that's not the case, what is going on in this project, what further checks am I not considering?