我的数据库表名是tripcomment
:
mysql> select * from orbit_tripcomments;
+----+------------------------+------------+------------+---------+---------------------+
| id | comment | citymap_id | ip_address | user_id | posted |
+----+------------------------+------------+------------+---------+---------------------+
| 2 | very nice comment 508 | 127.0.0.1 | 168 | 2014-11-20 08:25:19 |
| 3 | I make plan for visite | 508 | 127.0.0.1 | 168 | 2014-11-20 08:33:17 |
| 4 | i make a trip of manali| 508 | 127.0.0.1 | 168 | 2014-11-19 10:17:17 |
| 5 | i make a trip of manali| 508 | 127.0.0.1 | 168 | 2014-11-20 10:18:26 |
我的django查询是:
from datetime import datetime
from datetime import timedelta
tt = (datetime.utcnow() + timedelta(seconds=30)).strftime('%Y-%m-%d %H:%M:%S')
t_comment = models.tripcomments.objects.filter(citymap_id=parent_mapid,
posted__gte=tt)
但它返回一个空白列表。
答案 0 :(得分:0)
您应该为datetime
字段传递DateTime
个实例,而不是字符串:
from datetime import datetime, timedelta
results = Item.objects.filter(pub_date__lt=datetime.now() - timedelta(hours=5))