[Answered ]-Django filter column with OR statement

1👍

You just need to put filter first and then values_list.
This should work.

home_team_list2 = PreviousLossesNbav1WithDateAgg.objects.filter(
Q(away_team_field="Chicago") | Q(home_team_field="Chicago")
).values_list('actual_over_under_result_field', flat=True)

I tried this on my local machine and it worked fine.

SELECT `previous_losses_nbav1_with_date_agg`.`ACTUAL OVER UNDER RESULT:` 
FROM `previous_losses_nbav1_with_date_agg` WHERE 
(`previous_losses_nbav1_with_date_agg`.`AWAY TEAM:` = Chicago OR 
`previous_losses_nbav1_with_date_agg`.`HOME TEAM:` = Chicago)

This generated output of query is not valid SQL because "Django never actually interpolates the parameters: it sends the query and the parameters separately to the database adapter, which performs the appropriate operations." Source: code.djangoproject.com/ticket/17741

You need to replace ` with " and put ‘ around Chicago to make it work.

enter image description here

enter image description here

Leave a comment