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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With