Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 353
sorin Avatar asked Jun 09 '11 12:06

sorin


2 Answers

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).

like image 104
Tomasz Zieliński Avatar answered Oct 25 '22 09:10

Tomasz Zieliński


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.

like image 24
manji Avatar answered Oct 25 '22 09:10

manji