django:关键字不能是表达式
django :keyword can't be an expression
是否可以使用部分匹配来过滤对象。
我正在尝试 -
response = {}
pid = post['id'].split('_')[0]
response['product'] = list(product_details.objects.filter(p_id.split('_')[0] = pid).values())
但我收到错误 -
keyword can't be an expression
有没有更短的方法来执行任务。我想要 id
的第一部分与 post['id']
的第一部分匹配的对象
提前致谢。
使用 startswith
查找:
list(product_details.objects.filter(p_id__startswith=pid + '_').values())
是否可以使用部分匹配来过滤对象。
我正在尝试 -
response = {}
pid = post['id'].split('_')[0]
response['product'] = list(product_details.objects.filter(p_id.split('_')[0] = pid).values())
但我收到错误 -
keyword can't be an expression
有没有更短的方法来执行任务。我想要 id
的第一部分与 post['id']
提前致谢。
使用 startswith
查找:
list(product_details.objects.filter(p_id__startswith=pid + '_').values())