Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么这不起作用?State.objects.filter(pk__regex=r'^[0-9]')
State.objects.filter(pk__regex=r'^[0-9]')
我收到一个错误:
没有运算符与给定名称和参数类型匹配
正则表达式用于字符串,但 pk 是整数。
我不确定您要做什么,但是如果您只想获得 pk 介于 0 和 9 之间的所有状态,则可以使用范围:
State.objects.filter(pk__range=(0, 9))