Opened 6 years ago

Closed 5 years ago

Last modified 21 months ago

#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 Przemek Pawlas)

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.

Change History (6)

comment:1 by Przemek Pawlas, 6 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 6 years ago

Resolution: worksforme
Status: newclosed
Version: 2.2master

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.

comment:3 by Ralph Minderhoud, 5 years ago

Resolution: worksforme
Status: closednew

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>}
Version 0, edited 5 years ago by Ralph Minderhoud (next)

comment:4 by Mariusz Felisiak, 5 years ago

Resolution: worksforme
Status: newclosed
Summary: Django default_site admin configuration doesn't register anythingDjango default_site admin configuration doesn't register anything.
Triage Stage: UnreviewedAccepted

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.

in reply to:  description comment:5 by Przemek Pawlas, 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 Sergei Shishov, 21 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?

Last edited 21 months ago by Sergei Shishov (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top