简体   繁体   中英

How to show entire existing postgres database in Django admin view

I have an existing PostgreSQL database and I'd like to browse it within Django's admin view. How do you make all the existing tables in a database browsable in Django's admin view?

I tried following the steps here but I was only able to view Groups and Users. I also read that maybe I have to edit admin.py but I'm not sure where that file would be located and what I'd have to put in it.

You need to tell Django which tables you want to browse in the admin view. To manage database tables Django uses models . Your Django project should be divided into multiple apps and each app has its own modules such as models.py , view.py , admin.py etc.

So if you want to browse all the tables you need to add admin.py files in every app and in each admin.py file add the following lines to register the model with Django's admin .

from django.contrib import admin
from <your_app>.models import <your_model1>, <your_models2>

Now for each model that you imported add.

admin.site.register(<your_model1>)
admin.site.register(<your_model2>)

Please note that only those tables will be visible in Django admin which are managed by Django models . If you do not have a corresponding model for a table in your database you won't be able to view it in the admin.

To know more about the how the admin works read the Django documentation for your version of Django here . Also here is a good tutorial on configuring the admin view in Django.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM