From 2e463feb8dbd8f314d8347e44e4f3805425cddc2 Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Wed, 16 Oct 2019 14:11:07 +0300 Subject: [PATCH] Sort countries by name accordingly to locale --- apps/location/views/common.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/location/views/common.py b/apps/location/views/common.py index a1e6f011..99cd4c92 100644 --- a/apps/location/views/common.py +++ b/apps/location/views/common.py @@ -1,8 +1,9 @@ """Location app views.""" from rest_framework import generics from rest_framework import permissions - +from django.db.models.expressions import RawSQL from location import models, serializers +from utils.models import get_current_locale # Mixins @@ -37,7 +38,9 @@ class CountryListView(CountryViewMixin, generics.ListAPIView): """List view for model Country.""" pagination_class = None - + def get_queryset(self): + qs = super().get_queryset().order_by(RawSQL("name->>%s", (get_current_locale(),))) + return qs class CountryRetrieveView(CountryViewMixin, generics.RetrieveAPIView): """Retrieve view for model Country."""