From ff9bc8aa7047a7d85059ef0e05a0fc6c49599b2a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 26 Feb 2019 09:54:51 +0100 Subject: [PATCH] Automatically create PasswordFactor on initial setup closes #16 --- .../migrations/0014_auto_20190226_0850.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 passbook/core/migrations/0014_auto_20190226_0850.py diff --git a/passbook/core/migrations/0014_auto_20190226_0850.py b/passbook/core/migrations/0014_auto_20190226_0850.py new file mode 100644 index 0000000000..b5b8bb709f --- /dev/null +++ b/passbook/core/migrations/0014_auto_20190226_0850.py @@ -0,0 +1,25 @@ +# Generated by Django 2.1.7 on 2019-02-26 08:50 + +from django.db import migrations + + +def create_initial_factor(apps, schema_editor): + """Create initial PasswordFactor if none exists""" + PasswordFactor = apps.get_model("passbook_core", "PasswordFactor") + if not PasswordFactor.objects.exists(): + PasswordFactor.objects.create( + name='password', + slug='password', + order=0, + backends=[] + ) + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0013_invitation_needs_confirmation'), + ] + + operations = [ + migrations.RunPython(create_initial_factor) + ]