0

I have created a project using Golang. I have used PostgreSQL as the database. Now I want to make an admin panel for this project using Django. I want directly reflect the database tables in the Django admin panel. As I am not running the project under the Django server and I don't have any apps and models, how can I show them in the admin panel?

2 Answers2

1

What you want is to use an existing DB to be managed by the DJango admin. To do this you must create a django project and create the models for each table. This is very tedious so there is an official process so you don't have to do all this work and it is done automatically.

$ python manage.py inspectdb

https://docs.djangoproject.com/en/4.1/howto/legacy-databases/

Pablo
  • 364
  • 1
  • 10
0

First create an empty project in django then in settings.py set your database as postgreSQL

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': 'customers',
    'USER': 'root',
    'PASSWORD': '',
    'HOST': 'localhost',
    'PORT': '5432', 
}

}

make sure to create superuser for login in admin panel and proper urls for the same.

Add models in models.py and register it in admin.py

P.S - make sure you have installed psycopg2 using pip command.

  • My database already has existing tables. I don't want to redeclare any fields and constraints from Django models. Is there any other way? – Barun Bhattacharjee Dec 23 '22 at 08:03
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 25 '22 at 22:12