Django aggregation and filtering

in Django after aggregation.
if I use filterfor a column that is not aggregated,
I use it in the whereSQL statement sentence
and not in havingas expected.

follows an example:

I have a table of test results. Say I have TestA and TestB.

Version:   2    |   2   |   2
TestA   :Pass   |Null   |Fail
testB   :Error  |Fail   |Null

Each test can be run at any time.
I want to show the latest result for this test.

what i tried

x=Site.results.filter(timeEnd__isnull=False).values('idTest').annotate(Max('timeEnd'))

and then filtering x using:

x.filter(result=<number of result>)

but I get results using a second filter that does not appear in the original x.

How can I get the desired result?

but if I try to display:

result(Version=2).failedFilter()
TestA=Fail
TestB=Fail

result(Version=2).PassedFilter()
TestA=Pass

result(Version=2).ErrorFilter()
TestB=Error

result(version=2)
TestA=Fail
TestB=Fail

when, in addition to the Failed Filter, everything else should be empty.

Summary:

tables:
test
----
    id
    name

Site
----
    id
    name

testresult
----------
    id
    date
    testid
    siteid
    result(int)

.

+3
1

last() .

site = Site.objects.get(id=1)
for test in Test.objects.all():
        test_result = TestResult.objects.filter(site=site, test=test).latest('timeEnd')
        print test_result.result

annotate() , . , , timeEnd set, (, , ).

+1

All Articles