19

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

the
  • 21,007
  • 11
  • 68
  • 101
agiliq
  • 7,518
  • 14
  • 54
  • 74

9 Answers9

44

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
  • 45,304
  • 42
  • 117
  • 144
  • 1
    That's a good summary! It solves 90% of the issue with models not displaying in admin! +1 – Laurent May 13 '14 at 08:51
  • For me, `python manage.py runserver` didn't work because I was testing using a live server on port 80, so I had to enter the command `sudo service apache2 restart` and it updated the models I recently added to the admin website. – Rock Lee Feb 25 '15 at 21:08
  • django's `syncdb` is now deprecated since 1.7, use `python3 manage.py migrate` instead for newer versions of django – Liam O'Toole Jun 21 '21 at 10:49
13

In such a situation is also a good practice to check if the user logged in to the admin panel has rights to manage such a model. If they do then you could change your code to access the functions as root.

Perception
  • 79,279
  • 19
  • 185
  • 195
Jorge Con Jota
  • 489
  • 1
  • 6
  • 16
8

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

M. Ryan
  • 6,973
  • 11
  • 52
  • 76
  • 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). – TonyM Dec 03 '09 at 21:46
  • 1
    Changes yes, but development server doesn't pick up new files. – Kugel Dec 03 '09 at 23:34
  • 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 Dec 09 '09 at 00:38
  • 2
    an extra tip: after shutting down the server, delete all pyc files! – twig Sep 14 '12 at 01:20
  • Just restarting the server made the admin 'view' the registered models. Didn't need to migrate, etc. – mrmuggles Jun 20 '16 at 14:44
4

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
  • 52,040
  • 14
  • 137
  • 178
2

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
  • 298,606
  • 55
  • 578
  • 516
  • 4
    As of Django 1.7, `admin.autodiscover()` [is no longer required](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#discovery-of-admin-files) – Alasdair Sep 02 '14 at 09:25
1

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.

rinti
  • 1,273
  • 1
  • 12
  • 16
  • This 1,000x!!!! I just spent 2 hours tearing my hair out, going over 3 nearly identical apps, one of which was showing up, and two which weren't. I knew that the Admin site had them registered, as duplicate or invalid registration was throwing and error. Every "beginner" mistake that was cited on SO wasn't at issue. Then buried deep in this thread was your comment, and a facepalm for me. Thanks so much!! – jlovison Dec 19 '12 at 12:59
1

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
  • 1,078
  • 1
  • 9
  • 16
0

I've faced the same problem, but it was a little tricky than yours.

Consider, that you have a project with, say, five or even more apps. For me it is more obvious to register all models in just one admin.py file, so I have decided to do it in one place - core directory. Of course, it was not an app, so none of models showed up on admin page.

JohnShallow
  • 45
  • 1
  • 6
-1

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

admin.autodiscover()

urlpatterns = patterns('',
    ('^admin/', include(admin.site.urls)),
)
Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
ha22109
  • 8,036
  • 13
  • 44
  • 48