Reputation: 173
I'm trying to obtain data using django filter and connected to postgres database. The filter statement leads to error- 'ValueError: too many values to unpack (expected 2)'
Here is the sql equivalent and my attempt at creating a django filter query You would notice that I have used two columns for storing datetime, review_time_datetime and match_time_datetime
SQL Equivalent QUERY
SELECT *
FROM "table1" where review_time_datetime >'2021-06-14 00:00'
and match_time_datetime < '2021-06-14 24:00'
Django Filter QUERY
filter_query = table1.objects.filter(review_time_datetime, match_time_datetime)
Upvotes: 0
Views: 373
Reputation: 997
You could use something like this to lookup
import datetime
start_date = datetime.date(2005, 1, 1)
end_date = datetime.date(2005, 3, 31)
Table1.objects.filter(review_time_datetime__range=(start_date, end_date))
Read more https://docs.djangoproject.com/en/3.2/ref/models/querysets/#range
Upvotes: 0
Reputation: 652
Try using:
filter_query = table1.objects.filter(review_time_datetime__gt=from_date, match_time_datetime__lt=to_date)
Upvotes: 1