Django ORM between and usage

created at 07-16-2021 views: 1

Django ORM between and usage

sql statement

SELECT * FROM target WHERE ctime BETWEEN '2020/1/1 00:00:00' AND '2020/1/1 23:59:59'

Django ORM uses __range

from datetime import date
from datetime import timedelta
from datetime import datetime, time

pub_date =
min_pub_date_time = datetime.combine(pub_date, time.min) 
max_pub_date_time = datetime.combine(pub_date, time.max)

objs= Target.objects.filter(ctime__range = [min_pub_date_time, max_pub_date_time]).all()

objs= Target.objects.filter(ctime__range = ["2020/1/1 00:00:00", "2020/1/1 23:59:59"]).all()
Please log in to leave a comment.