Django Queryset: Cast VARCHAR field in SQL before filtering

China☆狼群 提交于 2019-12-02 05:01:59

as simple as it gets: use a regex query

regex = r'^0{0,4}%s ?$' % building_no
address = Address.objects.filter(building__iregex=regex)\

any hints on performance welcome...

try simple int(you string value)

for example:

str = "00100"
int(str)

will give 100 as integer value. same applies for

 str = "100100"
int(str)

gives 100100 as integer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!