开发者

Django query a model since its creation to an X time

开发者 https://www.devze.com 2023-03-29 07:03 出处:网络
Having a such model: class HelpRequest(models.Model): creation_tim开发者_如何学Pythone = models.DateTimeField(auto_now_add=True)

Having a such model:

class HelpRequest(models.Model):
    creation_tim开发者_如何学Pythone = models.DateTimeField(auto_now_add=True)

I want to query HelpRequest which are created within the last 5 mins, how can I achieve this?


import datetime
HelpRequest.objects.filter(creation_time__gte=(datetime.datetime.now() - datetime.timedelta(minutes=5)))
0

精彩评论

暂无评论...
验证码 换一张
取 消