diff --git a/apps/location/migrations/0036_auto_20200127_2004.py b/apps/location/migrations/0036_auto_20200127_2004.py new file mode 100644 index 00000000..af475a6a --- /dev/null +++ b/apps/location/migrations/0036_auto_20200127_2004.py @@ -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), + ] diff --git a/apps/location/models.py b/apps/location/models.py index a8f4c43a..36eb575a 100644 --- a/apps/location/models.py +++ b/apps/location/models.py @@ -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"}') diff --git a/apps/search_indexes/signals.py b/apps/search_indexes/signals.py index 0a6fb4f6..0f89139a 100644 --- a/apps/search_indexes/signals.py +++ b/apps/search_indexes/signals.py @@ -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',