【发布时间】:2010-05-28 21:26:41
【问题描述】:
具体来说,我正在尝试使用字符串来任意过滤 ORM。我已经尝试过 exec 和 eval 解决方案,但我遇到了困难。下面的代码不起作用,但这是我知道如何解释我要去哪里的最好方法
from gblocks.models import Image
f = 'image__endswith="jpg"' # Would be scripted in another area, but passed as text <user input>
d = Image.objects.filter(f)
#for the non-django pythonistas:
d = Image.objects.filter(image__endswith="jpg")
# would be the non-dynamic equivalent.
【问题讨论】:
标签: python