diff --git a/elections/migrations/0033_inactive_users.py b/elections/migrations/0033_inactive_users.py new file mode 100644 index 0000000..0c98cae --- /dev/null +++ b/elections/migrations/0033_inactive_users.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.6 on 2021-10-04 07:49 + +from django.db import migrations + + +def set_users_inactive(apps, schema_editor): + db_alias = schema_editor.connection.alias + User = apps.get_model("elections", "User") + + User.objects.using(db_alias).filter(election__isnull=False).update(is_active=False) + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections", "0032_auto_20210820_0023"), + ] + + operations = [ + migrations.RunPython(set_users_inactive, migrations.RunPython.noop), + ] diff --git a/elections/utils.py b/elections/utils.py index 32499f7..27dfc97 100644 --- a/elections/utils.py +++ b/elections/utils.py @@ -334,6 +334,7 @@ def create_users(election, csv_file): username=f"{election.id}__{username}", email=email, full_name=full_name, + is_active=False, ) for (username, full_name, email) in reader ]