Code

Ticket #8500: 8500.1.diff

File 8500.1.diff, 3.8 KB (added by jezdez, 4 years ago)

updated patch from #8572 by msaelices

Line 
1diff --git a/django/contrib/admin/__init__.py b/django/contrib/admin/__init__.py
2index abc5f09..ddaac3e 100644
3--- a/django/contrib/admin/__init__.py
4+++ b/django/contrib/admin/__init__.py
5@@ -8,7 +8,7 @@ from django.utils.importlib import import_module
6 # True while running, and False when it finishes.
7 LOADING = False
8 
9-def autodiscover():
10+def autodiscover(admin_site=None):
11     """
12     Auto-discover INSTALLED_APPS admin.py modules and fail silently when
13     not present. This forces an import on them to register any admin bits they
14@@ -27,6 +27,9 @@ def autodiscover():
15     import imp
16     from django.conf import settings
17 
18+    if admin_site is None:
19+        admin_site = site
20+
21     for app in settings.INSTALLED_APPS:
22         # For each app, we need to look for an admin.py inside that app's
23         # package. We can't use os.path here -- recall that modules may be
24@@ -55,5 +58,11 @@ def autodiscover():
25         # Step 3: import the app's admin file. If this has errors we want them
26         # to bubble up.
27         import_module("%s.admin" % app)
28+
29+        # Step 4: look for register function and call it, passing admin site
30+        # as parameter
31+        register_func = getattr(mod, 'register', None)
32+        if register_func is not None and callable(register_func):
33+            register_func(admin_site)
34     # autodiscover was successful, reset loading flag.
35     LOADING = False
36diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
37index 61bae28..e06b601 100644
38--- a/django/contrib/auth/admin.py
39+++ b/django/contrib/auth/admin.py
40@@ -138,6 +138,6 @@ class UserAdmin(admin.ModelAdmin):
41         }, context_instance=RequestContext(request))
42 
43 
44-admin.site.register(Group, GroupAdmin)
45-admin.site.register(User, UserAdmin)
46-
47+def register(site):
48+    site.register(Group, GroupAdmin)
49+    site.register(User, UserAdmin)
50diff --git a/django/contrib/comments/admin.py b/django/contrib/comments/admin.py
51index ede833f..7ed91de 100644
52--- a/django/contrib/comments/admin.py
53+++ b/django/contrib/comments/admin.py
54@@ -65,4 +65,5 @@ class CommentsAdmin(admin.ModelAdmin):
55 # Only register the default admin if the model is the built-in comment model
56 # (this won't be true if there's a custom comment app).
57 if get_model() is Comment:
58-    admin.site.register(Comment, CommentsAdmin)
59+    def register(site):
60+        site.register(Comment, CommentsAdmin)
61diff --git a/django/contrib/flatpages/admin.py b/django/contrib/flatpages/admin.py
62index b6fdba3..1fc5631 100644
63--- a/django/contrib/flatpages/admin.py
64+++ b/django/contrib/flatpages/admin.py
65@@ -25,4 +25,5 @@ class FlatPageAdmin(admin.ModelAdmin):
66     list_filter = ('sites', 'enable_comments', 'registration_required')
67     search_fields = ('url', 'title')
68 
69-admin.site.register(FlatPage, FlatPageAdmin)
70+def register(site):
71+    site.register(FlatPage, FlatPageAdmin)
72diff --git a/django/contrib/redirects/admin.py b/django/contrib/redirects/admin.py
73index a9b2a32..15662fb 100644
74--- a/django/contrib/redirects/admin.py
75+++ b/django/contrib/redirects/admin.py
76@@ -1,4 +1,3 @@
77-
78 from django.contrib import admin
79 from django.contrib.redirects.models import Redirect
80 
81@@ -8,4 +7,5 @@ class RedirectAdmin(admin.ModelAdmin):
82     search_fields = ('old_path', 'new_path')
83     radio_fields = {'site': admin.VERTICAL}
84 
85-admin.site.register(Redirect, RedirectAdmin)
86\ No newline at end of file
87+def register(site):
88+    site.register(Redirect, RedirectAdmin)
89diff --git a/django/contrib/sites/admin.py b/django/contrib/sites/admin.py
90index 2442c24..2102fa2 100644
91--- a/django/contrib/sites/admin.py
92+++ b/django/contrib/sites/admin.py
93@@ -6,4 +6,5 @@ class SiteAdmin(admin.ModelAdmin):
94     list_display = ('domain', 'name')
95     search_fields = ('domain', 'name')
96 
97-admin.site.register(Site, SiteAdmin)
98\ No newline at end of file
99+def register(site):
100+    site.register(Site, SiteAdmin)