Noah Clark
Noah Clark

Reputation: 8131

Django App Not Showing up in Admin Interface

I'm currently moving from my development server to an Apache web production server.

I've tried doing the following just by copying it over and I can login to the admin panel but it doesn't show up.

My admin.py in my app looks like this:

    import models
    from django.contrib import admin

    admin.site.register(models.Organization)

And here is my models.py

from django.db import models

class Organization(models.Model):
    name = models.CharField(max_length=100)
    website = models.URLField()
    azon_code = models.CharField(max_length=50)
    gooe_code = models.CharField(max_length=50)
    cj_code = models.CharField(max_length=50)

I've resyned the database and restarted apache as well thinking that might do something.

Upvotes: 14

Views: 16399

Answers (7)

MegaKenga
MegaKenga

Reputation: 13

In my case it turned out to be that apps should be registered in the order of creation (Django 4.2). Initially my INSTALLED_APPS looked like:

INSTALLED_APPS = [
'debug_toolbar',
'django.contrib.admin',
#some more django apps
'catalog.apps.CatalogConfig',
'files.apps.FilesConfig',
'cart.apps.CartConfig',
'django_celery_results',]

Then I added core app BEFORE first app - catalog

INSTALLED_APPS = [
'debug_toolbar',
'django.contrib.admin',
#some more django apps
'core.apps.CoreConfig',
'catalog.apps.CatalogConfig',
'files.apps.FilesConfig',
'cart.apps.CartConfig',
'django_celery_results',]

And it appeared that I MUST put apps in order of creation, otherwise last created app won't show in admin panel

INSTALLED_APPS = [
'debug_toolbar',
'django.contrib.admin',
#some more django apps
'catalog.apps.CatalogConfig',
'files.apps.FilesConfig',
'cart.apps.CartConfig',
'django_celery_results',
'core.apps.CoreConfig',]

Upvotes: 0

Hrithik Bhatt
Hrithik Bhatt

Reputation: 1

Your Imports in the admin.py is wrong i guess Try this way

from .models import *

Upvotes: 0

Krishna Jangid
Krishna Jangid

Reputation: 5410

in your admin.py file inside your main( first and default ) app of your project do this

in my case i have 3 app as follow

cityapp,stateapp,countryapp

so in my admin.py file i will add following line

from django.contrib import admin
from stateapp.models import State
from countryapp.models import Country
from cityapp.models import City

admin.site.register(Country)
admin.site.register(State)
admin.site.register(City)

it works in my case see

enter image description here

Upvotes: 2

Harun ERGUL
Harun ERGUL

Reputation: 5942

Another possible reason for not showing app in admin page is Apache doesn't have permissions. Sometimes we create an app with permission that Apache can't access it. If Apache doesn't have access it will not show. For linux users require to change app permissions.

sudo chown -R www-data:www-data app_name

This command will give permisson to Apache to access app folder recursively.

Upvotes: 1

Netro
Netro

Reputation: 7297

For me it was very silly reason. I have enabled permissions. Admin user didn't have the permission to access the models.

I gave the permission to admin user. It worked.

Upvotes: 12

leodotcloud
leodotcloud

Reputation: 1960

For those who are visiting this question, the above answer doesn't work directly in the current Django version(1.7.7).

The answer to the above question becomes:

from myapp.models import Organization
admin.site.register(Organization)

Upvotes: 3

Andrei Serdeliuc ॐ
Andrei Serdeliuc ॐ

Reputation: 5878

Aren't you supposed to import like:

from mysite.myapp.models import Organization
admin.site.register(Organization)

Upvotes: 21

Related Questions