Admin registrations have no effect with custom default admin site in the same package

I have a weird problem that’s already resolved, but I’d like to understand what’s going on. The app I’m working on is open source so you can take a look at everything.

I wanted to customize the default admin site, and so added a new AdminConfig/AdminSite to the app (not project), which didn’t work out of the box - docs said to add these onto the project level, and now it works. Except that I wanted to define the custom admin site in the app to not “pollute” the small project package.

  • If I define the custom AdminSite on the project level and register it as the default site in myproject.apps.AdminConfig everything works well.
  • If I do it on the app level and register myapp.admin.site.AdminSite, the site works… except that all admin registrations from myapp have no effect.

What’s going on in the latter case? Is the registration order wrong (custom admin config is the first entry in INSTALLED_APPS)?

I think you’d be better off showing both of those use cases as PRs. There are a number of things that could matter, so being as precise as possible is important. And if you can share the code along with a description of what it results in (error, something not showing), we’ll be able to help more.

With the current main branch (relevant changes in commit 0339557), I have a custom AdminSite class in the coriolis project package, and it works fine - Events is there and all is good:

If I move the custom AdminSite class to the events app and set default_site in AdminConfig to that moved class (on the django-admin-site-in-app branch - b82e6f4), Events are gone from that list above. There are no warnings, error messages or crashes, everything works correctly other than that the admin site no longer sees Events. Adding some prints on the module level shows the custom admin site package being imported.

The solution is to just keep it in the project package, but I’d like to understand why this happens.

I suspect if you rename that events.admin package to something everything would be fine. The reason is that the dot path of events.admin could be either the directory admin or the file admin.py.

Nope, my logic is wrong.

My bet is that this line Coriolis/__init__.py at b82e6f49d9cba41ba55c800a472e73a71fc09a02 · DragoonAethis/Coriolis · GitHub is causing your pain. Your models file is likely importing something that is conflicting. If you haven’t heard it already, don’t import a wildcard. It leads to difficult to debug situations like this.