from decouple import config

from jobs.settings import *

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test_db',
        'USER': 'postgres',
        'PASSWORD': 'pass1234',
        'HOST': 'db',
        'PORT': 5432,
    }
}

#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
#        'NAME': 'sqlite3.db',                      # Or path to database file if using sqlite3.
#        'USER': '',                      # Not used with sqlite3.
#        'PASSWORD': '',                  # Not used with sqlite3.
#        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
#        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
#    }
#}

from decouple import config

from jobs.settings import *

try:
    host = config('DB_HOST')
except:
    host = 'db'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test_db',
        'USER': 'postgres',
        'PASSWORD': 'pass1234',
        'HOST': host,
        'PORT': 5432,
    }
}

#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
#        'NAME': 'sqlite3.db',                      # Or path to database file if using sqlite3.
#        'USER': '',                      # Not used with sqlite3.
#        'PASSWORD': '',                  # Not used with sqlite3.
#        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
#        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
#    }
#}

Add logic for db host during runtime
Add logic for db host during runtime

  from decouple import config
  
  from jobs.settings import *
+ 
+ try:
+     host = config('DB_HOST')
+ except:
+     host = 'db'
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'test_db',
          'USER': 'postgres',
          'PASSWORD': 'pass1234',
-         'HOST': 'db',
+         'HOST': host,
          'PORT': 5432,
      }
  }
  
  #DATABASES = {
  #    'default': {
  #        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
  #        'NAME': 'sqlite3.db',                      # Or path to database file if using sqlite3.
  #        'USER': '',                      # Not used with sqlite3.
  #        'PASSWORD': '',                  # Not used with sqlite3.
  #        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
  #        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
  #    }
  #}
  
Add logic for db host during runtime
## Code Before:
from decouple import config

from jobs.settings import *

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test_db',
        'USER': 'postgres',
        'PASSWORD': 'pass1234',
        'HOST': 'db',
        'PORT': 5432,
    }
}

#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
#        'NAME': 'sqlite3.db',                      # Or path to database file if using sqlite3.
#        'USER': '',                      # Not used with sqlite3.
#        'PASSWORD': '',                  # Not used with sqlite3.
#        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
#        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
#    }
#}

## Instruction:
Add logic for db host during runtime
## Code After:
from decouple import config

from jobs.settings import *

try:
    host = config('DB_HOST')
except:
    host = 'db'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test_db',
        'USER': 'postgres',
        'PASSWORD': 'pass1234',
        'HOST': host,
        'PORT': 5432,
    }
}

#DATABASES = {
#    'default': {
#        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
#        'NAME': 'sqlite3.db',                      # Or path to database file if using sqlite3.
#        'USER': '',                      # Not used with sqlite3.
#        'PASSWORD': '',                  # Not used with sqlite3.
#        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
#        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
#    }
#}
