localized cities #1

This commit is contained in:
Kuroshini 2020-01-27 23:13:14 +03:00
parent a8fc46ed60
commit 468527bc0e
3 changed files with 45 additions and 2 deletions

View File

@ -0,0 +1,41 @@
# Generated by Django 2.2.7 on 2020-01-27 20:04
from django.db import migrations, models
import utils.models
def clear_data(apps, schema_editor):
City = apps.get_model('location', 'City')
for city in City.objects.all():
city.name = None
city.save()
def preserve_field_data(apps, schema_editor):
City = apps.get_model('location', 'City')
for city in City.objects.all():
city.name = city.name_translated
city.save()
class Migration(migrations.Migration):
dependencies = [
('location', '0035_auto_20200115_1117'),
]
operations = [
migrations.AlterField(
model_name='city',
name='name',
field=models.CharField(max_length=250, null=True, verbose_name='name'),
),
migrations.RunPython(clear_data, migrations.RunPython.noop),
migrations.AlterField(
model_name='city',
name='name',
field=utils.models.TJSONField(default=None, help_text='{"en-GB":"some city name"}', null=True, verbose_name='City name json'),
),
migrations.RunPython(preserve_field_data, migrations.RunPython.noop),
]

View File

@ -145,7 +145,9 @@ class CityQuerySet(models.QuerySet):
class City(models.Model):
"""Region model."""
name = models.CharField(_('name'), max_length=250)
name = TJSONField(default=None, null=True, help_text='{"en-GB":"some city name"}',
verbose_name=_('City name json'))
name_translated = TJSONField(blank=True, null=True, default=None,
verbose_name=_('Translated name'),
help_text='{"en-GB":"some text"}')

View File

@ -13,7 +13,7 @@ def update_document(sender, **kwargs):
app_label_model_name_to_filter = {
('location', 'country'): 'address__city__country',
('location', 'city'): 'address__city',
# ('location', 'city'): 'address__city',
('location', 'address'): 'address',
# todo: remove after migration
('establishment', 'establishmenttype'): 'establishment_type',