improve superuser creation
This commit is contained in:
parent
93be13ccd1
commit
d1db825995
|
@ -14,6 +14,7 @@ from pathlib import Path
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
DATA_DIR = Path("/tmp").resolve()
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
|
@ -77,7 +78,7 @@ WSGI_APPLICATION = 'homemanager.wsgi.application'
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': '/tmp/db.sqlite3',
|
'NAME': DATA_DIR / 'db.sqlite3',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
STATIC_ROOT = '/tmp/static'
|
STATIC_ROOT = DATA_DIR / 'static'
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
|
@ -9,18 +9,20 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from homemanager.settings import DATABASES
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'homemanager.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'homemanager.settings')
|
||||||
|
|
||||||
data = Path("/tmp/db.sqlite3")
|
|
||||||
if not data.is_file():
|
|
||||||
from django.core.management import call_command
|
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SUPERUSER_PASSWORD', 'password')
|
|
||||||
call_command("migrate --noinput")
|
|
||||||
call_command("collectstatic --noinput")
|
|
||||||
call_command("createsuperuser --noinput --username adp --email a@a.com")
|
|
||||||
call_command("createsuperuser --noinput --username fabian --email b@a.com")
|
|
||||||
|
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
||||||
|
data = DATABASES["default"]["NAME"]
|
||||||
|
if not data.is_file():
|
||||||
|
from django.core.management import call_command
|
||||||
|
call_command("migrate", "--noinput")
|
||||||
|
call_command("collectstatic", "--noinput")
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
User = get_user_model()
|
||||||
|
User.objects.create_superuser('adp', 'a@a.com', 'password')
|
||||||
|
User.objects.create_superuser('fabian', 'b@a.com', 'password')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue