Fix database config

This commit is contained in:
Rodolfo Carvalho 2015-05-22 15:34:11 +02:00
parent 83a388343b
commit fcf0ccde53
3 changed files with 28 additions and 9 deletions

View file

@ -173,8 +173,16 @@
"value": "${DJANGO_SECRET_KEY}" "value": "${DJANGO_SECRET_KEY}"
}, },
{ {
"name": "DATABASE_URL", "name": "DATABASE_USER",
"value": "postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@$DATABASE_SERVICE_HOST:$DATABASE_SERVICE_PORT/${DATABASE_NAME}" "value": "${DATABASE_USER}"
},
{
"name": "DATABASE_PASSWORD",
"value": "${DATABASE_PASSWORD}"
},
{
"name": "DATABASE_NAME",
"value": "${DATABASE_NAME}"
} }
] ]
} }

View file

@ -12,7 +12,6 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
import dj_database_url
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -80,10 +79,23 @@ WSGI_APPLICATION = 'project.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases # https://docs.djangoproject.com/en/1.8/ref/settings/#databases
if os.getenv("DATABASE_SERVICE_HOST"):
DATABASES = { DATABASES = {
'default': dj_database_url.config( 'default': {
default='sqlite:///'+os.path.join(BASE_DIR, 'db.sqlite3') 'ENGINE': 'django.db.backends.postgresql_psycopg2',
) 'NAME': os.getenv("DATABASE_NAME"),
'USER': os.getenv("DATABASE_USER"),
'PASSWORD': os.getenv("DATABASE_PASSWORD"),
'HOST': os.getenv("DATABASE_SERVICE_HOST"),
'PORT': os.getenv("DATABASE_SERVICE_PORT"),
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
} }

View file

@ -2,4 +2,3 @@ Django==1.8.1
psycopg2==2.6 psycopg2==2.6
gunicorn==19.3.0 gunicorn==19.3.0
whitenoise==1.0.6 whitenoise==1.0.6
dj-database-url==0.3.0