简体   繁体   中英

Django's Admin Interface for Read-Only Model?

I have a Django model whose fields are read-only, populated from a database.

I have found that the admin interface is a great way to visualize my data, but whenever I try using it, I run into a problem: It seems to require write access to the database, which I don't have.
(ie it tries to create tables called auth_user , django_session , etc. in the read-only database... I managed to disable the latter but can't disable the former.)

How do I use the admin interface with read-only access?

Or, if this is not possible:

How do I make a temporary database (hopefully in memory, or on disk if necessary) to make it happy?

I figured out how to do this:

  • Create an in-memory database (use :memory: as the database) for the internal data
  • Use a database router for redirecting the reads to the other database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM