accessing various schemas in Django admin interfac

2019-08-05 05:52发布

I am using mysql database. I have many schemas with many tables. I want to create a Django admin interface for various tables in different schemas. Currently for a single schema I am using a setting like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'schema1',                      
        'USER': 'test',                     
        'PASSWORD': 'test',                  
        'HOST': 'example.abc.com',                     
        'PORT': '',                      
    }

After creating an app, admin interface is created for whatever models I register in the admin.py of that app for this schema. Now I want to create an other app where I register models of another schema in its admin.py. These models will belong to different schema. Now how do I create an admin interface for the second app that points to different schema?

Is it possible to create two Django projects with two different settings.py and two different admin interfaces? (So that each will point to different schema.)

I have googled a lot about this. But couldn't find any info. May be there is a simple way and I am approaching this in a wrong way. Any help is appreciated.

Thanks in advance.

2条回答
我只想做你的唯一
2楼-- · 2019-08-05 06:20

I'm not quite sure if you mean that you want to handle different databases or just have different models registered. If you want to have different models in different admin sites, you can register multiple admin sites with different models. You can then access one site eg with '/admin' the other with '/otheradmin'. Maybe you find django-admin-tools useful to customize the display of your models/apps within the admin!

查看更多
登录 后发表回答