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 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):
|
class Migration(migrations.Migration):
|
||||||
|
|
@ -9,15 +22,34 @@ class Migration(migrations.Migration):
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
migrations.RunPython(forwards, backwards),
|
||||||
|
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='user',
|
model_name='user',
|
||||||
name='language',
|
name='language',
|
||||||
field=models.CharField(
|
field=models.CharField(
|
||||||
choices=[('en-gb', 'English (British)'), ('ar-ar', 'العربية'), ('cs-cz', 'Česky'), ('da-dk', 'Dansk'),
|
choices=[
|
||||||
('de-de', 'Deutsch'), ('en-us', 'English (American)'), ('es-es', 'Español'),
|
('en-gb', 'English (British)'),
|
||||||
('fr-fr', 'Français'), ('hi-in', 'हिंदी'), ('it-it', 'Italiano'), ('ja-jp', '日本語'),
|
('ar-ar', 'العربية'),
|
||||||
('kk-kz', 'Қазақ'), ('nl-nl', 'Nederlands'), ('pl-pl', 'Polska'), ('pt-br', 'Português'),
|
('cs-cz', 'Česky'),
|
||||||
('ro-ro', 'Română'), ('ru-ru', 'Русский'), ('zh-hans', '简体中文')], default='en-gb',
|
('da-dk', 'Dansk'),
|
||||||
max_length=7),
|
('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