[英]How to filter a queryset of objects created more than one hour ago from Django's DateTimeField?
问题:
我正在尝试过滤一个 model,其中状态在一个多小时内没有改变。
我试过的:
Product.objects.filter(
Q(status="PENDING"),
Q(created__hour__gt=1)
).all().order_by("-created")
预期解决方案:获取状态为“PENDING”但在一个多小时内未更改的对象的查询集。
你过滤:
from datetime import timedelta
from django.db.models.functions import Now
Product.objects.filter(
status="PENDING", created__lt=Now()-timedelta(hours=1)
).order_by('-created')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.