开发者

Django Nested Filter Values

This line works and returns the value that I'm looking for:

logs = Log.objects.filter(filterURI=aFilter.uri).values()[0]['yk']

However, when I try to add another filter and do the same I get errors:

logs = Log.objects.filter(filterURI=aFilter.uri).filt开发者_StackOverflow社区er(k=k-1).values()[0]['yk']

My understanding is that a object.filter returns a queryset but so does a 'filter of a filter'. So I should be able to do the 'values' call in the same way regardless of whether I have one filter or 1000.

What am I doing wrong here.

Thanks in advance.


I don't think the error is in the fact that you have two filters - it's in the actual second filter. k=k-1 will only work if you have both a model field and a local variable called k - the first is on the left of the expression, the second on the right.

If you want to refer to the model field on the right of the expression, use F:

.filter(k=(F('k')-1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜