我知道我可以使用python自己的功能工具集,但我希望在Django中有一种方法。
我有这个型号:
class AssetGeoFenceEvent(models.Model):
#...
#assets, for which this event is assigned
asset = models.ForeignKey(Asset)
#...
,引用的Asset
模型如下:
class Asset(models.Model):
#...
client = models.ForeignKey(Client)
#....
我以为我能做到:
#get all the registered events for this client
events = AssetGeoFenceEvent.objects.filter(asset.client == client)
但是失败并出现错误:
关键字不能是表达式
试过这个,但它失败了:
#get all the registered events for this client
events = AssetGeoFenceEvent.objects.filter(lambda a: a.client == client)
这给了我一个错误
'function'对象不可迭代
那么我怎么能用Django来解决这个问题?
答案 0 :(得分:6)
events = AssetGeoFenceEvent.objects.filter(asset__client=client)