diff --git a/apps/location/migrations/0041_auto_20200210_1124.py b/apps/location/migrations/0041_auto_20200210_1124.py new file mode 100644 index 00000000..e9609003 --- /dev/null +++ b/apps/location/migrations/0041_auto_20200210_1124.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.7 on 2020-02-10 11:24 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('location', '0040_auto_20200203_1454'), + ] + + operations = [ + migrations.AddField( + model_name='city', + name='created', + field=models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Date created'), + ), + migrations.AddField( + model_name='city', + name='modified', + field=models.DateTimeField(auto_now=True, verbose_name='Date updated'), + ), + ] diff --git a/apps/location/models.py b/apps/location/models.py index 16841e5c..53c1b8d9 100644 --- a/apps/location/models.py +++ b/apps/location/models.py @@ -182,7 +182,7 @@ class CityQuerySet(models.QuerySet): return self.prefetch_related('country', 'region', 'region__country') -class City(models.Model, TranslatedFieldsMixin): +class City(TranslatedFieldsMixin, ProjectBaseMixin): """Region model.""" name = TJSONField(default=None, null=True, help_text='{"en-GB":"some city name"}', verbose_name=_('City name json')) diff --git a/apps/location/views/back.py b/apps/location/views/back.py index 4e23513d..a7eab166 100644 --- a/apps/location/views/back.py +++ b/apps/location/views/back.py @@ -138,7 +138,7 @@ class CityListCreateView(common.CityViewMixin, generics.ListCreateAPIView): def get_queryset(self): """Overridden method 'get_queryset'.""" qs = models.City.objects.all().annotate(locale_name=KeyTextTransform(get_current_locale(), 'name'))\ - .order_by('locale_name').with_base_related() + .order_by('-modified').with_base_related() if self.request.country_code and self.request.query_params.get('country_code') is None: qs = qs.by_country_code(self.request.country_code) return qs