拥有这样的模型:
class HelpRequest(models.Model):
creation_time = models.DateTimeField(auto_now_add=True)
我想查询最近5分钟内创建的HelpRequest,我该如何实现?
答案 0 :(得分:3)
import datetime
HelpRequest.objects.filter(creation_time__gte=(datetime.datetime.now() - datetime.timedelta(minutes=5)))