可以使用.upper()检入django rest查询过滤器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了可以使用.upper()检入django rest查询过滤器相关的知识,希望对你有一定的参考价值。

如何在将两者都更改为大写后将db中的值与request.data进行比较。这样可能吗?

str_code = CustomerAccount.objects.filter(strAccountCode.upper() = 
request.data['strAccountCode'].upper(),chrDocumentStatus='N')
答案

您可以使用不区分大小写的完全匹配,iexact过滤器:

str_code = CustomerAccount.objects.filter(
    strAccountCode__iexact=request.data['strAccountCode'],
    chrDocumentStatus='N'
)

转换为SQL将会是这样的:

SELECT ... WHERE strAccountCode ILIKE '[value]';

以上是关于可以使用.upper()检入django rest查询过滤器的主要内容,如果未能解决你的问题,请参考以下文章