From ad46b7ad63b87364aba687efd4535c43017daf35 Mon Sep 17 00:00:00 2001 From: Sarah Withee <2601974+geekygirlsarah@users.noreply.github.com> Date: Tue, 21 Jan 2025 21:26:00 -0500 Subject: [PATCH] Add in Postgres support + load in DATABASE_URL from env --- AttendanceV2/settings.py | 7 +++++-- requirements.txt | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/AttendanceV2/settings.py b/AttendanceV2/settings.py index f6df1cf..93431c9 100644 --- a/AttendanceV2/settings.py +++ b/AttendanceV2/settings.py @@ -9,7 +9,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.1/ref/settings/ """ - +import os +import dj_database_url from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -80,7 +81,9 @@ "NAME": BASE_DIR / "db.sqlite3", } } - +# Update database info if it's in $DATABASE_URL environment variable +db_from_env = dj_database_url.config(conn_max_age=500) +DATABASES["default"].update(db_from_env) # Password validation # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators diff --git a/requirements.txt b/requirements.txt index 570771e..4773dc0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Django~=5.1.4 autoflake~=2.3.1 -black~=24.10.0 \ No newline at end of file +black~=24.10.0 +dj-database-url==2.1.0 +psycopg2~=2.9.10 \ No newline at end of file