[Django]-Model not showing up in django admin

38πŸ‘

βœ…

Hmmmm…Try change include of your app in settings.py:

From:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'game',
    ....

To:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'YOUR_PROJECT.game',# OR 'YOUR_PROJECT.Game'
πŸ‘€Saff

204πŸ‘

The problem reported can be because you skipped registering the models for the admin site. This can be done, creating an admin.py file under your app, and there registering the models with:

from django.contrib import admin
from .models import MyModel

admin.site.register(MyModel)
πŸ‘€jesicadev18

36πŸ‘

Had the same issue with Django 2.0.

The following code didn’t work:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from users import models

admin.register(models.User, UserAdmin)

It turns out the line

admin.register(models.User, UserAdmin)

should have been

admin.site.register(models.User, UserAdmin)

Since I didn’t get any warnings, just wanted to point out this thing here too.

πŸ‘€Pavel Vergeev

10πŸ‘

I know this has already been answered and accepted, but I felt like sharing what my solution to this problem was, maybe it will help someone else.

My INSTALLED_APPS looked like this:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'core',  # <---- this is my custom app
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    'south',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

See, I put my app before Django’s admin app, and apparently it loads them in that order. I simply moved my app right below the admin, and it started showing up πŸ™‚

πŸ‘€Eduard Luca

6πŸ‘

For Django 1.10 helped to me to register the Model following way with (admin.ModelAdmin) at the end

from django.contrib import admin

from .models import YourModel
admin.register(YourModel)(admin.ModelAdmin)
πŸ‘€pymen

6πŸ‘

I had the same issue. Done everything right. But I didn’t have permission to view the model.

Just give the required permission (view/add/edit/etc) and then check again.

Give Permission using admin panel:

  1. Login to the site using the credentials for your superuser account.
  2. The top level of the Admin site displays all of your models, sorted by "Django application". From the Authentication and Authorization section, you can click the Users or Groups links to see their existing records.
  3. Select and add the required permission

Select and add the required permission
enter image description here

refer this to add/change permission through the admin panel

Alternative:
Using code
refer Official Django Doc

πŸ‘€Keval

5πŸ‘

It’s probably very rare but I had an issue today where the permissions on the admin.py file I had created were corrupt and thus made it unreadable by django. I deleted the file and recreated it with success.

Hope that saves someone, should they stumble here with my problem.

πŸ‘€bitwit

5πŸ‘

I struggled with registering my models (tried all the suggestions above) too until I did a very simple thing. I moved my admin.py out of the directory up to the project directory – refreshed the admin screen and moved it back and voila into the models app directory – they all appeared instantly. I’m using PyCharm so not sure if that was causing some problems.

My setup is exactly what the Django manual says –

models.py

class xxx(models.Model):
    ....
    def __str__(self):  # __str__ for Python 3, __unicode__ for Python 2
        return self.name

admin.py

from .models import xxx
admin.site.register(xxx)
πŸ‘€Rob Mascaro

4πŸ‘

I am using digital ocean and also ran into this issue. The solution was a service restart. I used

service gunicorn restart

and that got the model to show up

πŸ‘€Michael Fox

3πŸ‘

I just had to restart apache service. service apache2 restart. Then new models shown up.

3πŸ‘

I had the same issue. Few of my models were not showing in the django admin dashbaord because I had not registered those models in my admin.py file.

//Import all the models if you have many

from store.models import *

admin.site.register(Order)
admin.site.register(OrderItem)

This fixed it for me. Just register and refresh your webpage and the models will be visible in the admin dashboard

πŸ‘€Om Prakash N

2πŸ‘

I have the same problem. I solve this to add register of admin to admin.py.
And I don’t need to add extra class.

Like:

from jalka.game.models import Game
from django.contrib import admin

admin.site.register(Game)

Enviroment: Win10、Django 1.8

πŸ‘€sos418

2πŸ‘

I had the same issue and i resolved it as follow
first go to your app.py file and copy the class name.

from django.apps import AppConfig

class **ResumeConfig**(AppConfig):
name = 'resume'

now go to setting.py and place it in application definition as follow:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
**'resume.apps.ResumeConfig'**
]

save and run the commands in the terminal

python manage.py makemigrations
python manage.py migrate

run your server and go to /admin
your problem will be solved

2πŸ‘

you just need to register your model.
got to admin.py file of the same app and write,

from .models import "Modelname"

admin.site.register(("Modelname")) 
#create tuple to register more than one model
πŸ‘€ANURAG SHARMA

1πŸ‘

I would also like to add, that I did everything these answers said, except I did not enter on the command line sudo service apache2 restart which I needed to make the changes take effect. (Because I was testing on a live server on port 80 on amazon web services. I was also using an Ubuntu operating system.) That solved it for me. I hope this might help somebody.

πŸ‘€Rock Lee

1πŸ‘

I got the same issue,
After restart my development server model is showing in admin page.

πŸ‘€Muthuraj S

1πŸ‘

Change your admin code to this:

from django.contrib import admin
from .models import Game

class GameAdmin(admin.ModelAdmin):
  list_display    = ['type', 'teamone', 'teamtwo', 'gametime']

admin.site.register(Game, GameAdmin)

Also make sure the app is included in settings.py file and make sure you’re importing the right name for your model. Another reason that can bring about this issue is putting a comma (,) at the end of your model fields as though it a python list.

πŸ‘€Romeo

1πŸ‘

My new model not showing up on Admin page due to me using ADMIN_REORDER(https://pypi.org/project/django-modeladmin-reorder/) in settings.py to control model order, added a while back and forgotten. Added the new model to settings.py and it shows up.

πŸ‘€Emily

0πŸ‘

Adding to what Saff said, your settings.py should be like this:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'YOUR_PROJECT',
    # And
    'YOUR_PROJECT.Foo',
    'YOUR_PROJECT.Bar',
)
πŸ‘€phreeLynx

0πŸ‘

The mistake might be at views.pyin your β€œdef” you should check if you got

If mymodel.is_valid():
mymodel = model.save()

I will give you a piee of my code so you would understand it

@login_required(login_url='/home/')
def ask_question(request):
user_asking = UserAsking()

if request.method == "POST":
    user_asking = UserAsking(request.POST)

    if user_asking.is_valid():
        user_asking.save()

    return redirect(home)

return render(request, 'app/ask_question.html', {
    'user_asking': user_asking,
})

`UserAsking is a form.
i hope i did help you

πŸ‘€danil2000

0πŸ‘

One of the possible reasons is that you do not close old python processes.

0πŸ‘

I had a similar issue on an instance of django mounted in a docker container. The code was correct but changes to admin.py were not appearing in django admin.

After quitting the django process and remounting the container with docker-compose up, the added models became available in django admin.

πŸ‘€FlyingJay

0πŸ‘

I had all my Admin classes in a folder ./sites/ which only worked because of cercular dependencies I had. I fixed them, and everything else stopped working.

When I renamed that directory from ./sites/ to ./admin/ it worked.

πŸ‘€Daniel W.

0πŸ‘

Another thing to point out is that you should make sure you’re signed in with a superuser.

It could be that you are signed in with a user who has limited permission on view capacity so try that.

I in Django 2.0 I still register my app using just the name of the app i.e β€˜game’. But the issue was in the logged in user permissions.

0πŸ‘

I was updating a remote server with code from local, but the remote server was still using the old models in the admin screen. Everything looked exactly the same between my local and the remote server – the database tables matched and the code was also identical.

The problem turned out the remote server was running using the venv environment. After running source venv/bin/activate and then doing the migrations, the admin showed all the new models.

πŸ‘€Oliver

0πŸ‘

If you have multiple models to register then use.

admin.site.register((Model1 , Model2 , Model3))

or

admin.site.register([Model1 , Model2 , Model3])

in your admin.py file.

0πŸ‘

I have the same error but I have not mentioned my app in INSALLED_APPS

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'myapp.apps.myappConfig',
)

I have already registered the model but forgot to mention my app in INSTALLED_APPS and after mentioning it works for me

0πŸ‘

For me, migration was an issue. If you created this new app, try doing the following:

python manage.py makemigrations <name_of_your_app>
python manage.py migrate <name_of_your_app>

You do not need to include all admin.site.register in a single app, you could specify them in their corresponding app at the admin.py file.

0πŸ‘

I had this same issue, django=4.0 with docker-compose i was not using ModelAdmin, turns out registering multiple Models in one call to admin.site.register errors out when running migration.

So doing

admin.site.register(ModelA, ModelB)

did not work. instead, you I did something like

admin.site.register(ModelA)
admin.site.register(ModelB)

I hope it helps anyone dockerizing their Django App

0πŸ‘

Give your user "Superuser status" through the edit user functionality in the admin panel.

enter image description here

Most probably the user you are signed in is not a superuser and doesn’t have the required permissions for the newly created models.

In Django, after new models are created and migrated, the permissions of the existing users are not updated. Only the users with Superuser status can by default view, add, change and delete records for these models.

To fix the problem and avoid it in the future give "Superuser status" to your development user.

πŸ‘€svet

-1πŸ‘

You Make sure You have Added your Model to
admin.py file .

Example : if your model is Contact.

from django.contrib import admin

from .models import Contact
admin.site.register((Contact))

Now your issue might be resolved if not try restarting your server.

πŸ‘€Utkarsh verma

-2πŸ‘

You only have to import(include) this:

from models import *
πŸ‘€user10149671

Leave a comment