开发者

How to implement django admin on an existing database where you have read-only access?

I want to use Django admin to browse and existing database but I want 开发者_开发技巧to be sure that me or Django are not going to do any modifications to this database.

For this reason I think I should use two database, one that is the read-only one and one that would store other django tables, one where I have read-write access.

I know how to define multiple databases in settings.py but I don't know how to force django to use another database for specific models.


As a supplement to manji's answer - you can also use database VIEWs and expose some tables as read-only ones. Using VIEWs with Django is a powerful technique that allows exposing abritrarily complex lookups as Django models.

In your case you could e.g. create additional database with VIEWs mirroring the relevant tables from the original database, and create additional Django project with only admin enabled for those tables - or something along these lines (you know your use case better than me).


You can use Automatic database routing to configure read/write operations database for each model

Or

You can also customize Admin interface read/write operations database (Exposing multiple databases in Django's admin interface) with the using argument of the querysets.

In both cases, set read/write database as default (django models will be saved there) and explicitly route queries to your readonly database for your models.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜