Sort countries by name accordingly to locale
This commit is contained in:
parent
4e005a7a4d
commit
2e463feb8d
|
|
@ -1,8 +1,9 @@
|
||||||
"""Location app views."""
|
"""Location app views."""
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from rest_framework import permissions
|
from rest_framework import permissions
|
||||||
|
from django.db.models.expressions import RawSQL
|
||||||
from location import models, serializers
|
from location import models, serializers
|
||||||
|
from utils.models import get_current_locale
|
||||||
|
|
||||||
|
|
||||||
# Mixins
|
# Mixins
|
||||||
|
|
@ -37,7 +38,9 @@ class CountryListView(CountryViewMixin, generics.ListAPIView):
|
||||||
"""List view for model Country."""
|
"""List view for model Country."""
|
||||||
|
|
||||||
pagination_class = None
|
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):
|
class CountryRetrieveView(CountryViewMixin, generics.RetrieveAPIView):
|
||||||
"""Retrieve view for model Country."""
|
"""Retrieve view for model Country."""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user