Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registered models do not show up in admin

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?

like image 860
agiliq Avatar asked Dec 03 '09 13:12

agiliq


People also ask

How do I automatically register all models in Django admin?

To automate this process, we can programmatically fetch all the models in the project and register them with the admin interface. Open admin.py file and add this code to it. This will fetch all the models in all apps and registers them with the admin interface.

How do I register a user model in Django admin?

from django. contrib import admin # Register your models here. Register the models by copying the following text into the bottom of the file. This code imports the models and then calls admin.

What happens if Django admin is not recognized?

'django-admin' is not recognized as an internal or external command, operable program or batch file. To fix this, first close the terminal window and relaunch it with administrator privileges. Once you launch the elevated terminal window change directory to where you wish to start your Django project.


2 Answers

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
like image 102
Thierry Lam Avatar answered Oct 09 '22 21:10

Thierry Lam


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.

like image 39
Jorge Con Jota Avatar answered Oct 09 '22 22:10

Jorge Con Jota