views:

25

answers:

1

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).filter(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.

A: 

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)
Daniel Roseman
The k value to the left of the equal is the model field, the value to the right of the equal sign is calculated, simply k-1, and it does not refer to the model field. The 'k' in k-1 is passed in above.
Przemek