[Fixed]-Django admin not showing models

21đź‘Ť

âś…

Did you run syncdb after changing your models.py file?

Go to the base directory of your project (where manage.py is) and run

python manage.py syncdb

Edit: Since you already tried this, add a str or unicode method to your class like this:

class Resource(models.Model):

    title = models.CharField(max_length=128, blank=True)

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

Edit 2: Funnily enough, I ran into the exact same issue today working on my own projects. If the str code above still doesn’t work for you, double check that you’ve actually registered your models in admin.py:

from MyApp.models import MyModel
admin.site.register(MyModel)

Edit 3: Finally, make sure your admin.py file with the above code is actually inside the directory of the app in question (i.e. the same directory with your models.py that defines MyModel).

👤Gravity Grave

20đź‘Ť

Make sure you are calling:

admin.site.register(<model-name>)

and not

admin.register(<model-name>)

This was the cause for me.

9đź‘Ť

Double check your permissions – that is: if you think your user is a superuser, just go look to make sure! If your user is not a superuser, look in your “Authentication and Authorization” › “Users” under the user you are logged in as and see if the “User permissions:” include the models for the application in question.

After chasing this for longer than I care to admit, I realized my user was not actually a superuser. As you will see on many of the related posts, it is easy for an application to not show in Admin if the user does not have the correct permissions, such as here:
enter image description here

As you can see from this, user 2 does not have the required permissions on the “done” app’s models – only on the “timekeeping” app’s models.

I was fairly certain this was a superuser (but it’s not). I figure either I must have reduced my permissions to troubleshoot an issue another user had been seeing or to give a more representative experience using the system.

PS A giveaway for this being the issue is that any clean database where you use the python manage.py createsuperuser to get going will show all of your registered apps/models whereas an existing database (where permissions may be more nuanced) will show only some of your registered apps/models.

👤sage

2đź‘Ť

Check that you have admin.autodiscover() in urls.py.

0đź‘Ť

This happens to my case, it may not be the same as yours.

Check if you have admin.pyc being created, if it is not being created then it is not being called. If it is not being called then one of the cause is you have xrdb/xrdb/admin folder with __init__.py in it.

I guess there can be other ways to do this but for me I created a file that would look to your case as publications_admin.py inside xrdb/xrdb/admin and add import xrdb.admin.publications_admin inside xrdb/xrdb/admin/__init__.py.

Do the registration inside publications_admin.py, that would look something like.

from django.contrib import admin
from xrdb.models import Publications

admin.site.register(Publications)

I hope it helps.
Cheers!

👤redwud

-1đź‘Ť

Step 1: Delete all the migrations from migrations folder.

step 2: Go to root directory and type

python manage.py makemigrations publications

Note: publications here is your sub-app name

xrdb # Main directory folder

├── xrdb # Main app

├── publications # Sub app

step 3:

python manage.py sqlmigrate publications 0001

Note : 0001 is migrations file name

This will solve your problem

Cheers!!

👤Udit Arora

Leave a comment