Skip to content
Advertisement

Django filter on combination using F

I wrote the following query using the Django ORM:

JavaScript

With this I’m trying to filter out each fixture where the prediction__value for the home is greater than 0.0 and the prediction__value of the away is greater than 0.0.

Sadly my query is returning 0 records upon using .count() whereas it should return almost every record.

When I only use one part of the query; so either the home or the away part the query does return a certain amount of records.

The models:

JavaScript

The value of league is irrelevant here.

Advertisement

Answer

You should filter with two outer JOIN’s, so:

JavaScript

This will thus look for Predictions in the given fixture where one prediction is from the home team and its value is greater than 0, and a predication from the away team that is greater than 0.

Advertisement