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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30402>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> Steps:
> 1. I have project X with app Y, which has admin folder with site.py and
> multiple specific_model.py.
> 2. In site.py I extend AdminSite with SocialAuthAdminSite.
> 3. In specific_model.py files I use admin.site.register(Model,
> ModelAdmin)
> 4. In project/apps.py I extend AdminConfig with SocialAuthAdminConfig
> which has default_site = 'X.Y.admin.site.SocialAuthAdminSite'
> 5. In settings I load X.apps.SocialAuthAdminConfig
>
> 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.
New description:
Steps:
1. I have project X with app Y, which has admin folder with site.py and
multiple specific_model.py.
2. In site.py I extend AdminSite with SocialAuthAdminSite.
3. In specific_model.py files I use admin.site.register(Model, ModelAdmin)
4. In project/apps.py I extend AdminConfig with SocialAuthAdminConfig
which has default_site = 'X.Y.admin.site.SocialAuthAdminSite'
5. 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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/30402#comment:1>
* status: new => closed
* version: 2.2 => master
* resolution: => worksforme
Comment:
Thanks for the report, however it works for me. Can you take a look at
[https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#overriding-the-
default-admin-site overriding-the-default-admin-site] documentation and
double-check all steps? You can also check how we use it in our
[https://github.com/django/django/tree/master/tests/admin_default_site
test suite].
Please use one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels] if you will have further questions.
--
Ticket URL: <https://code.djangoproject.com/ticket/30402#comment:2>
* status: closed => new
* resolution: worksforme =>
Comment:
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>}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30402#comment:3>
* status: new => closed
* resolution: => worksforme
* stage: Unreviewed => Accepted
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30402#comment:4>
Comment (by Przemek Pawlas):
@felixxm Where does it state that in the documentation? Examples are for
project dir I guess, but examples =/= requirements
--
Ticket URL: <https://code.djangoproject.com/ticket/30402#comment:5>
Comment (by sshishov):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30402#comment:6>