2

I have a question related to Django handling different databases. I have this doubt because, I need to create a database for different countries. And, my webapp has one dns, and only one. I want to be able to handle different countries with the same dns.

I have this questions in my mind but, I don't know which one is the best practice for this kind of situations...

1- In a Django Project create different apps, for each country and use a Database Router to differentiate. As: if model._meta.app_label == 'customer_data': return 'customer_db'

2 - Store a db name on session and when user logs in, sends every requests to the database related to the user. (don't have any clue of how to do this)

I don't know what else I can do, besides the ones I described above. Any senior django developer, can help me with this question? and, if possible provide articles which can help me understand better... Thank you.

Max
  • 41
  • 6
  • 1
    Seems like option 2 might be a good bet. Have a look at [this](https://stackoverflow.com/a/21382032/8868327). I'd stay clear from option 1 though... – EDG956 Aug 01 '22 at 14:23
  • 1
    Django provides currently no simple way to support multiple tenants using the same project instance, even when only the data is different. Because we don’t want you running many copies of your project, you’ll be able to have: https://django-tenants.readthedocs.io/en/latest/ – Siva Sankar Aug 01 '22 at 15:39

0 Answers0