代码如下:

# 获取三个小时内的数据
hour_ago = datetime.datetime.now() - datetime.timedelta(hours=3)
current_time = datetime.datetime.now()
online_obj=models.table.objects.filter(create_time__gt=hour_ago,create_time__lt=current_time)