Create superuser and set site name by default on first run.

This commit is contained in:
Casper V. Kristensen 2019-10-25 03:35:15 +02:00
parent f78c32db85
commit 7c7ffee1f3
Signed by: caspervk
GPG key ID: 289CA03790535054
4 changed files with 57 additions and 2 deletions

View file

@ -31,8 +31,9 @@ Setup virtual environment and install dependencies:
python3 -m venv venv python3 -m venv venv
source venv/bin/activate source venv/bin/activate
pip install -r requirements.txt pip install -r requirements.txt
deactivate logout
``` ```
Add the uwsgi configuration file, `/etc/uwsgi/apps-available/drakul.ini`: Add the uwsgi configuration file, `/etc/uwsgi/apps-available/drakul.ini`:
```ini ```ini
[uwsgi] [uwsgi]
@ -67,6 +68,7 @@ Enable the application in uwsgi:
ln -s /etc/uwsgi/apps-available/drakul.ini /etc/uwsgi/apps-enabled ln -s /etc/uwsgi/apps-available/drakul.ini /etc/uwsgi/apps-enabled
service uwsgi restart service uwsgi restart
``` ```
Add the following to your `/etc/nginx/sites-available/drakul.example.com`: Add the following to your `/etc/nginx/sites-available/drakul.example.com`:
```text ```text
location / { location / {
@ -79,7 +81,7 @@ location /static/ {
} }
``` ```
That's it! After restarting nginx everything should work. That's it! After restarting nginx everything should work. The default superuser username/password is `admin`/`admin`.
### Environment variables ### Environment variables

View file

@ -0,0 +1,25 @@
# Generated by Django 2.2.6 on 2019-10-25 03:16
from django.db import migrations
def set_site_name(apps, schema_editor):
"""
https://docs.djangoproject.com/en/2.2/topics/migrations/#data-migrations
"""
Site = apps.get_model("sites", "Site")
Site.objects.create(
domain="drakul.example.com",
name="Drakul"
)
class Migration(migrations.Migration):
dependencies = [
("sites", "0001_initial"),
]
operations = [
migrations.RunPython(set_site_name),
]

View file

View file

@ -0,0 +1,28 @@
# Generated by Django 2.2.6 on 2019-10-25 03:09
from django.db import migrations
def create_admin(apps, schema_editor):
"""
https://docs.djangoproject.com/en/2.2/topics/migrations/#data-migrations
"""
# The docs says to use 'User = apps.get_model("users", "User")', but when doing that
# 'self.model.normalize_username()', which is called from create_superuser(), cannot be accessed..
from drakul.users.models import User
User.objects.create_superuser(
username="admin",
email="admin@localhost",
password="admin"
)
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.RunPython(create_admin),
]