jsocol / django-adminplus

Easily add custom views to the Django admin.
BSD 3-Clause "New" or "Revised" License
589 stars 79 forks source link

Missing core models from admin after adding adminplus #42

Open stretch4x4 opened 8 years ago

stretch4x4 commented 8 years ago

Hi,

Just spent today integrating adminplus into our Django 1.8.7 site, found an issue where 3 of our admin screens went missing after the upgrade.Turns out they are all core models (Groups, Users and Sites) and these are all added by an autodiscover that django runs before it loads the urls file. See traceback for when the first one is added: traceback Saw this in a previous issue and it has solved the issue for now although I am hoping someone smarter than I can help us solve it better:

import copy
from django.contrib import admin
from django.conf.urls import patterns, include, url

from adminplus.sites import AdminSitePlus

old = admin.site
admin.site = AdminSitePlus()
admin.site._registry = copy.copy(old._registry)
athre0z commented 8 years ago

Seems like monkey-patching admin.site isn't enough anymore. In Django 1.7, a decorator for registering models into the admin was introduced, which defaults to registering them into admin.sites.site. The authentication module is using this decorator. admin.site is just a copy generated through __ALL__, from admin.sites.site.

To fix the issue, in your urls.py, do

admin.site = AdminSitePlus()
admin.sites.site = admin.site
admin.autodiscover()

Edit: Thus, #43 is a duplicate of this issue.

AnnaDamm commented 7 years ago

For me, this works properly. Could you add that to the readme/documentation?

oliwarner commented 6 years ago

Or patch AdminSitePlus with a site property to point to itself.

Talkless commented 3 months ago

Just got hit by the same issue.

Workaround:

admin.site = AdminSitePlus()
admin.sites.site = admin.site
admin.autodiscover()

worked.