Skip to content
Snippets Groups Projects
Commit f6625580 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch '137-re-introduce-data-migrations' into 'master'

Resolve "Re-introduce data migrations"

Closes #137

See merge request AlekSIS/AlekSIS!112
parents f82b22af c43ebd2a
No related branches found
No related tags found
1 merge request!112Resolve "Re-introduce data migrations"
Pipeline #602 failed
from django.db import migrations, models
from datetime import date
def create_or_mark_current_term(apps, schema_editor):
db_alias = schema_editor.connection.alias
SchoolTerm = apps.get_model('core', 'SchoolTerm') # noqa
if not SchoolTerm.objects.filter(current=True).exists():
if SchoolTerm.objects.using(db_alias).exists():
term = SchoolTerm.objects.using(db_alias).latest('date_start')
term.current=True
term.save()
else:
SchoolTerm.objects.using(db_alias).create(date_start=date.today(), current=True)
class Migration(migrations.Migration):
dependencies = [
('core', '0005_add_verbose_names_meta'),
]
operations = [
migrations.RunPython(create_or_mark_current_term)
]
from django.contrib.auth import get_user_model
from django.db import migrations
def create_superuser(apps, schema_editor):
User = get_user_model()
if not User.objects.filter(is_superuser=True).exists():
User.objects.create_superuser(
username='admin',
email='root@example.com',
password='admin'
).save()
class Migration(migrations.Migration):
dependencies = [
('core', '0006_create_default_term'),
]
operations = [
migrations.RunPython(create_superuser)
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment