Sort countries by name accordingly to locale

This commit is contained in:
Kuroshini 2019-10-16 14:11:07 +03:00
parent 4e005a7a4d
commit 2e463feb8d

View File

@ -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."""