我正在尝试按日期过滤出版物,使用此代码但尝试一下,我收到此错误
from datetime import datetime, timedelta
from_date = datetime.now() - timedelta(days=7)
data = Entry.objects.filter(date_publication=[from_date, datetime.now()])
[u“'[datetime.datetime(2014,2,24,18,27,9,451000),datetime.datetime(2014,2,17,18,27,9,451000)]'tiene un formato不正确.Debe ser del tipo YYYY-MM-DD HH:MM [:ss [.uuuuuu]] [TZ]。“]
class Productos(models.Model):
...
date_publication = models.DateTimeField(auto_now=True)
...
帮助我! :)
答案 0 :(得分:0)
您可以尝试:
data = Entry.objects.filter(date_publication__gte=from_date, date_publication__lte=datetime.now())