[Django] #30402: Django default_site admin configuration doesn't register anything

37 views
Skip to first unread message

Django

unread,
Apr 25, 2019, 7:43:38 AM4/25/19
to django-...@googlegroups.com
#30402: Django default_site admin configuration doesn't register anything
-----------------------------------------+------------------------
Reporter: Destroy666x | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30402>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 25, 2019, 7:45:12 AM4/25/19
to django-...@googlegroups.com
#30402: Django default_site admin configuration doesn't register anything
-------------------------------+--------------------------------------

Reporter: Destroy666x | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Destroy666x:

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>

Django

unread,
Apr 26, 2019, 2:26:57 AM4/26/19
to django-...@googlegroups.com
#30402: Django default_site admin configuration doesn't register anything
--------------------------------+--------------------------------------
Reporter: Przemek Pawlas | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: worksforme

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by felixxm):

* 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>

Django

unread,
Jun 3, 2019, 2:48:24 PM6/3/19
to django-...@googlegroups.com
#30402: Django default_site admin configuration doesn't register anything
--------------------------------+--------------------------------------
Reporter: Przemek Pawlas | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by rminderhoud):

* 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>

Django

unread,
Jun 4, 2019, 2:11:21 AM6/4/19
to django-...@googlegroups.com
#30402: Django default_site admin configuration doesn't register anything.
--------------------------------+--------------------------------------
Reporter: Przemek Pawlas | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: worksforme
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by felixxm):

* 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>

Django

unread,
Jul 8, 2019, 8:56:40 AM7/8/19
to django-...@googlegroups.com
#30402: Django default_site admin configuration doesn't register anything.
--------------------------------+--------------------------------------
Reporter: Przemek Pawlas | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: worksforme
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

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>

Django

unread,
Mar 17, 2023, 5:37:43 AM3/17/23
to django-...@googlegroups.com
#30402: Django default_site admin configuration doesn't register anything.
--------------------------------+--------------------------------------
Reporter: Przemek Pawlas | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: dev

Severity: Normal | Resolution: worksforme
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages