Is it possible to arrange case-insensitive with first_name using Django-rest-framework.
Here is the code:
import django_filter class PersonFilter(django_filters.FilterSet): class Meta: model = Person fields = ('first_name_lower',) order_by = ('first_name_lower',) class PersonViewSet(BaseModelViewSet): queryset = Person.objects.all() permission_classes = (permissions.IsAuthenticated,) filter_backends = (filters.DjangoFilterBackend,) filter_class = PersonFilter
Is there an easy way to do case-insensitive ordering with django-filter ?
Here django-filter has documents for case insensitive search , but nothing for ordering ... p>
In Django docs, the code is somewhat dumb for this, which makes me wonder if it exists for django-filter or not. Here's a snippet of Django docs code on how to do this with Django ORM:
>>> from django.db.models.functions import Lower >>> MyModel.objects.order_by(Lower('myfield'))
source share