diff --git a/vibes_auth/migrations/0003_alter_user_language.py b/vibes_auth/migrations/0003_alter_user_language.py index 311eacc5..39be35b6 100644 --- a/vibes_auth/migrations/0003_alter_user_language.py +++ b/vibes_auth/migrations/0003_alter_user_language.py @@ -1,6 +1,19 @@ -# Generated by Django 5.2 on 2025-05-20 19:06 - from django.db import migrations, models +from django.db.models.functions import Lower + + +def forwards(apps, schema_editor): + User = apps.get_model('vibes_auth', 'User') + User.objects.all().update(language=Lower('language')) + + +def backwards(apps, schema_editor): + User = apps.get_model('vibes_auth', 'User') + for u in User.objects.all(): + parts = u.language.split('-', 1) + if len(parts) == 2: + u.language = f"{parts[0].lower()}-{parts[1].upper()}" + u.save(update_fields=['language']) class Migration(migrations.Migration): @@ -9,15 +22,34 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RunPython(forwards, backwards), + migrations.AlterField( model_name='user', name='language', field=models.CharField( - choices=[('en-gb', 'English (British)'), ('ar-ar', 'العربية'), ('cs-cz', 'Česky'), ('da-dk', 'Dansk'), - ('de-de', 'Deutsch'), ('en-us', 'English (American)'), ('es-es', 'Español'), - ('fr-fr', 'Français'), ('hi-in', 'हिंदी'), ('it-it', 'Italiano'), ('ja-jp', '日本語'), - ('kk-kz', 'Қазақ'), ('nl-nl', 'Nederlands'), ('pl-pl', 'Polska'), ('pt-br', 'Português'), - ('ro-ro', 'Română'), ('ru-ru', 'Русский'), ('zh-hans', '简体中文')], default='en-gb', - max_length=7), + choices=[ + ('en-gb', 'English (British)'), + ('ar-ar', 'العربية'), + ('cs-cz', 'Česky'), + ('da-dk', 'Dansk'), + ('de-de', 'Deutsch'), + ('en-us', 'English (American)'), + ('es-es', 'Español'), + ('fr-fr', 'Français'), + ('hi-in', 'हिंदी'), + ('it-it', 'Italiano'), + ('ja-jp', '日本語'), + ('kk-kz', 'Қазақ'), + ('nl-nl', 'Nederlands'), + ('pl-pl', 'Polska'), + ('pt-br', 'Português'), + ('ro-ro', 'Română'), + ('ru-ru', 'Русский'), + ('zh-hans', '简体中文'), + ], + default='en-gb', + max_length=7, + ), ), ]