2015-04-04 34 views
0

是否可以使用部分匹配來過濾對象。django:關鍵字不能是表達式

我想 -

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']的第一部分匹配的對象

在此先感謝。

+0

因爲這將使錯誤 - '太多值unpack' – aquaman 2015-04-04 12:53:13

回答

1

使用startswith查找:

list(product_details.objects.filter(p_id__startswith=pid + '_').values()) 
相關問題