In my Django Rest Framework project, I have a custom filter_backends that allows filtering by case insensitively:
class CaseInsensitiveOrderingFilter(OrderingFilter):
def filter_queryset(self, request, queryset, view):
ordering = self.get_ordering(request, queryset, view)
if ordering:
new_ordering = []
for field in ordering:
# field = str(field)
print(Lower(field))
if field.startswith('-'):
new_ordering.append(Lower(field[1:]).desc())
else:
new_ordering.append(Lower(field).asc())
return queryset.order_by(*new_ordering)
return queryset
This works fine in development.
Now I hosted the django app on elastic beanstalk and I configured a postgresql database via amazon relational database service (RDS).
When I try now to call the API, I get this error:
ProgrammingError at /api/profile_list/ function lower(bigint) does not exist LINE 1: ..."."author_id") GROUP BY "user_user"."id" ORDER BY LOWER(COUN...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
This error appears only in the RDS deployment.
I tried to type cast the fields in django with:
field = str(field)
But this is not working. Is there any way to allow caseinsensitive ordering without the lower function, or how can I conditionally check if it is a number (and cast then?) or a text abd