views:

277

answers:

7

I added a model to admin via admin.site.register, and it does not show up in admin. Sice admin is so "It just works", I have no idea of how to debug this. POinters?

A: 

Have you added the application to your installed apps? That has happened to me both one and two times. :) Otherwise it would be useful for us to see the code to help you.

Baresi
+3  A: 

When in doubt, shut down server, syncdb, start server.

Jasconius
Definite +1 for this comment. I thought the development server would pick up any changes in admin.py files - couldn't guarantee that 100%Restarting the server made a world of difference (in a positive way).
tonemcd
Changes yes, but development server doesn't pick up new files.
Kugel
I tend to always have my settings.py file open and a quick hack to reboot the server is to modify the settings file, which causes the Dev server to pick up any new changes.
Ralph Willgoss
+9  A: 

After adding and registering your admin:

# app/admin.py
class YourModelAdmin(admin.ModelAdmin):
    pass

admin.site.register(YourModel, YourModelAdmin)

Make sure your app is in your project settings.py:

# settings.py
INSTALLED_APPS = (
    # other apps ...
    'app',
)

Sync your project for that model if you have not done so already:

python manage.py syncdb

Restart your server, CTRL-C:

python manage.py runserver
Thierry Lam
+1 for picking up the most likely causes.
Dominic Rodger
+1  A: 

Also make sure there are no syntax errors in your admin.py or anything. That can cause an app to fail to be registered with the AdminSite.

Josh Ourisman
A: 

I think the checklist in Thierry's answer is almost definitive, but make sure that urls.py contains admin.autodiscover() to load INSTALLED_APPS admin.py modules.

# urls.py
from django.conf.urls.defaults import *
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    ('^admin/', include(admin.site.urls)),
)

More info in the django docs.

Alasdair
+2  A: 

I have the experience, that sometimes after changing an admin.py the dev-sever won't be restarted. in that case touch settings.py helps.

vikingosegundo
+1 good little trick
Ralph Willgoss
A: 

comment out the some lines in urls.py see docs for more details

admin.autodiscover()

urlpatterns = patterns('', ('^admin/', include(admin.site.urls)), )

ha22109