Features: 1) Add forwards and backwards migration logic for language field normalization using Lower; 2) Enhance allowed choices formatting in language field for improved readability;
Fixes: None; Extra: 1) Minor code cleanup and reorganization in migration file;
This commit is contained in:
parent
6b71695d86
commit
6678b84de2
1 changed files with 40 additions and 8 deletions
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue