0

Related to my earlier question in regards extending Django's AdminSite, I have sucessfully subclassed AdminSite and can log in perfectly fine. However, my admin site has no application models in it! The admin.autodiscover() function no longer works, and I'm simply not skilled enough with Python to figure out what I'm doing wrong!

Long story short, if I cannot use AdminSite.autodiscover(), how do I load all of the models in my verious Django apps into my subclassed AdminSite instance?

Community
  • 1
  • 1
TC Fox
  • 980
  • 4
  • 13
  • 25
  • If you could show us the code how you override the `AdminSite` it'll help us understand why its not working. – Marconi Jul 25 '12 at 08:45
  • 1
    This [answer](http://stackoverflow.com/a/3206933/113962) to a similar stack overflow question should help. – Alasdair Jul 25 '12 at 08:57
  • Ah, of course, how stupid of me. I'll edit this shortly with a couple of code snippets. (I'm clearly way too tired today!) – TC Fox Jul 25 '12 at 08:59

2 Answers2

1

There's no reason not to use the django.contrib.admin.autodiscover, even if you subclassed AdminSite. This is the actual instrumentation that imports the admin module from all your Django applications registered in settings.INSTALLED_APPS, effectively registering the models with your admin site instance.

To recap if you have a project.admin.foo_site instance of your project.admin.FooAdminSite subclass:

# project/urls.py
from django.conf.urls import url
from django.contrib import admin

from project.admin import foo_site


admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(foo_site.urls)),
)

#project/app/admin.py
from project.admin import foo_site
from project.app.models import Bar


foo_site.register(Bar)
Filip Dupanović
  • 32,650
  • 13
  • 84
  • 114
0

You need to set up an admin.py and register your models. Here's a paraphrased version from the Django Tutorial:

To do this, create a file called admin.py in your app directory, and edit it to look like this:

from django.contrib import admin
from app.models import Model1, Model2, Model3

admin.site.register(Model1)
admin.site.register(Model2)
admin.site.register(Model3)
mVChr
  • 49,587
  • 11
  • 107
  • 104