feat: add settings management

This commit is contained in:
2026-06-12 00:55:14 +02:00
parent eb05d56986
commit f3c11cbe28
6 changed files with 91 additions and 15 deletions
+24
View File
@@ -0,0 +1,24 @@
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
BASE_DIR = Path(__file__).resolve().parent.parent
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=BASE_DIR / ".env", env_file_encoding="utf-8")
django_secret_key: str = ""
debug: bool = True
allowed_hosts: list[str] = []
api_secret: str = "selecta-secret"
db_engine: str = "django.db.backends.postgresql"
db_name: str = "selecta-highscore"
db_user: str = "postgres"
db_password: str = ""
db_host: str = "localhost"
db_port: int = 5432
settings = Settings()
+12 -15
View File
@@ -12,20 +12,13 @@ https://docs.djangoproject.com/en/6.0/ref/settings/
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
from app.config import settings as env
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-i_1=_f%do@*t&q)!n^jh3cotravax72+65ctwm6u@slbdu+nr_"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
SECRET_KEY = env.django_secret_key
DEBUG = env.debug
ALLOWED_HOSTS = env.allowed_hosts
# Application definition
@@ -40,7 +33,7 @@ INSTALLED_APPS = [
"scores",
]
API_SECRET = "selecta-secret"
API_SECRET = env.api_secret
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
@@ -77,8 +70,12 @@ WSGI_APPLICATION = "app.wsgi.application"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": env.db_engine,
"NAME": env.db_name,
"USER": env.db_user,
"PASSWORD": env.db_password,
"HOST": env.db_host,
"PORT": env.db_port,
}
}