From 4cf7b0d499358e89549d6ae37dbcbc8520619ead Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 26 Nov 2016 13:17:38 +0000 Subject: [PATCH] Allow overriding of database url --- project/settings.py | 10 ++++++++-- requirements.txt | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/project/settings.py b/project/settings.py index 8d4edc3..91d7c4e 100755 --- a/project/settings.py +++ b/project/settings.py @@ -1,4 +1,5 @@ import os +import dj_database_url BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -97,11 +98,16 @@ WSGI_APPLICATION = 'project.wsgi.application' # Database # https://docs.djangoproject.com/en/1.10/ref/settings/#databases -DATABASES = { - 'default': { +if 'DATABASE_URL' in os.environ: + DATABASE_CONFIG = dj_database_url.config(default=os.environ['DATABASE_URL'], conn_max_age=300) +else: + DATABASE_CONFIG = { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } + +DATABASES = { + 'default': DATABASE_CONFIG } diff --git a/requirements.txt b/requirements.txt index 8758eef..b99e122 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ coverage==4.2 +dj_database_url==0.4.1 Django>=1.10,<1.11 flake8==3.2.1 honcho==0.7.1