0

In my django project i have to differenziate database name by user. i would to create a table, or a field in user table with database name and in settings.py insert related values checking user connected, but i have two doubt:

  1. How can i insert into DATABASES dict new variable?

    DATABASES = {
      'default': {
        'ENGINE': 'django.db.test.postgresql',
        'NAME': myvar,
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',
        'PORT': '5432',
      }
    }
    
  2. Settings.py is read before table and db instantiation, how is possible passing values after login?

There is another pythonic way to achieve this result?

Thanks in advance

Madhan Varadhodiyil
  • 2,086
  • 1
  • 14
  • 20
Manuel Santi
  • 1,106
  • 17
  • 46
  • There's is not thread safe way (web applications need to be thread safe) to do that. – Klaus D. Sep 03 '18 at 12:17
  • Possible duplicate of [Multi-tenant Django applications: altering database connection per request?](https://stackoverflow.com/questions/16721051/multi-tenant-django-applications-altering-database-connection-per-request) – dirkgroten Sep 03 '18 at 13:17

0 Answers0