29 lines
840 B
Python
29 lines
840 B
Python
from django.db import migrations
|
|
|
|
|
|
def sync_status_flags(apps, schema_editor):
|
|
User = apps.get_model("accounts", "User")
|
|
for user in User.objects.all():
|
|
if user.status == "inactive":
|
|
user.is_active = False
|
|
user.is_staff = False
|
|
user.is_superuser = False
|
|
elif user.status == "superadmin":
|
|
user.is_active = True
|
|
user.is_staff = False
|
|
user.is_superuser = True
|
|
else:
|
|
user.is_active = True
|
|
user.is_superuser = False
|
|
user.save(update_fields=["is_active", "is_staff", "is_superuser", "updated_at"])
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("accounts", "0003_user_status"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(sync_status_flags, migrations.RunPython.noop),
|
|
] |