In my Django app, I have a routing.py
helper module with a get_route
function that is used by my app. Before I can call this function, I need to build a graph network, which is slow (seconds), so I want to do this once instead of on every get_route
call. I build my graph network based on data in my database, so I need to access models (read-only) during this initialization. This question is similar but as pointed out there, the accepted answer is wrong, since it relies on django's AppConfig.ready(), but as is pointed out in the docs, if you make database queries in there, they will access your production database instead of your test database when running tests. Is there a way to do one-time initialization after Django has loaded the database?
Asked
Active
Viewed 17 times
0

Luciano
- 426
- 2
- 9
- 19