make settings more generic

This commit is contained in:
Jonathan Baecker 2020-05-05 11:38:35 +02:00
parent 02e815eb36
commit 8310002f95
4 changed files with 25 additions and 27 deletions

View File

@ -1,17 +1,15 @@
### Backend Apps
If you planing to extend the Backend with you own apps (api endpoints),
just add you app folder in **ffplayout/apps**.
If you planing to extend the backend with your own apps (api endpoints),
just add your app in folder: **ffplayout/apps**.
If you planing to us a DB, put a **db.py** file in your app. With this `Class`:
If you planing to us a DB, put a **settings.py** file in your app. With this object:
```
class Connector:
config = {
```python
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db-name.sqlite3'),
}
}
```

View File

@ -1,11 +0,0 @@
import os
BASE_DIR = os.path.dirname(os.path.abspath(os.path.join(__file__)))
class Connector:
config = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

View File

@ -0,0 +1,10 @@
import os
BASE_DIR = os.path.dirname(os.path.abspath(os.path.join(__file__)))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

View File

@ -120,12 +120,13 @@ for dir in os.listdir(APPS_DIR):
# add app to installed apps
INSTALLED_APPS += (app_name, )
if os.path.isfile(os.path.join(APPS_DIR, dir, 'db.py')):
db_conn = locate('{}.db.Connector.config'.format(app_name))
if os.path.isfile(os.path.join(APPS_DIR, dir, 'settings.py')):
db = locate('{}.settings.DATABASES'.format(app_name))
if list(db_conn.keys())[0] not in DATABASES:
for key in db:
if key not in DATABASES:
# add app db to DATABASES
DATABASES.update(db_conn)
DATABASES.update({key: db[key]})
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/