#30402 closed Bug (worksforme)
Django default_site admin configuration doesn't register anything.
Reported by: | Przemek Pawlas | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Steps:
- I have project X with app Y, which has admin folder with site.py and multiple specific_model.py.
- In site.py I extend AdminSite with SocialAuthAdminSite.
- In specific_model.py files I use admin.site.register(Model, ModelAdmin)
- In project/apps.py I extend AdminConfig with SocialAuthAdminConfig which has default_site = 'X.Y.admin.site.SocialAuthAdminSite'
- In settings I load X.apps.SocialAuthAdminConfig (tried at the beginnning, end, etc. - I don't think it matters)
Expected:
Admin classes for models should be registered like they were before I made edits to use default_site (before I just assigned the site to a variable and used that).
Actual:
Admin classes for models are not registered. The customized admin works otherwise though.
Change History (6)
comment:1 by , 6 years ago
Description: | modified (diff) |
---|
comment:2 by , 6 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Version: | 2.2 → master |
comment:3 by , 6 years ago
Resolution: | worksforme |
---|---|
Status: | closed → new |
Hello,
I believe there is still a bug here but I am not familiar enough with the django internals to pinpoint it. I have a similar issue as Przemek where using a custom AdminSite
and overriding default_site
works except that any newly registered models do not appear in the admin. It would seem the current test passes since the new class is indeed used but there is no test case to validate that the registry is correct. Here is an example of my setup:
settings.py
INSTALLED_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "myproject.apps.AdminConfig", "myproject.apps.AppConfig", ]
apps.py
from django.apps import AppConfig as DefaultAppConfig from django.contrib.admin.apps import AdminConfig as DefaultAdminConfig class AdminConfig(DefaultAdminConfig): default_site = "myproject.admin.AdminSite" class AppConfig(DefaultAppConfig): name = "myproject" verbose_name = "MyProject"
admin.py
from django.contrib import admin from .models import MyModel class AdminSite(admin.AdminSite): pass class MyModelAdmin(admin.ModelAdmin): pass admin.site.register(MyModel, MyModelAdmin)
Seemingly, everything is configured correctly as per the documentation. However, if we inspect the registry at the end of admin.py
and then again in urls.py
I notice that they don't match.
Command: print(admin.site._registry)
Registry in admin.py {<class 'myproject.models.MyModel'>: <myproject.admin.MyModelAdmin object at 0x7f5e5bc90fd0>}
Registry in urls.py {<class 'django.contrib.auth.models.Group'>: <django.contrib.auth.admin.GroupAdmin object at 0x7f5e5bc9c7f0>, <class 'django.contrib.auth.models.User'>: <django.contrib.auth.admin.UserAdmin object at 0x7f5e5bc48780>}
In my admin, the autodiscovered models appear (group, user) but the model I registered does not.
comment:4 by , 6 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Summary: | Django default_site admin configuration doesn't register anything → Django default_site admin configuration doesn't register anything. |
Triage Stage: | Unreviewed → Accepted |
Thanks for an extra info, however you should customize a default admin site inside a main project directory (like described in the documentation) not in an app.
comment:5 by , 5 years ago
@felixxm Where does it state that in the documentation? Examples are for project dir I guess, but examples =/= requirements
comment:6 by , 22 months ago
The issue is still here. We are trying to override the default site for django to django-otp
and it is not working. Following exact steps how it is indicated in the documentation.
Please make sure that crude monkeypatch like admin.site.__class__ = OTPAdminSite
will work and suggested everywhere but in my opinion it should not be suggested as proper solution.
NOTE: it is working if you comment out the main django.contrib.admin
from the site and do not touch the name of admin config override. But this information is not in documentation, no?
Thanks for the report, however it works for me. Can you take a look at overriding-the-default-admin-site documentation and double-check all steps? You can also check how we use it in our test suite.
Please use one of support channels if you will have further questions.