How do I do date math in a Django ORM query?

I'm using Django with Python 3.7. I have teh below model ...

class Article(models.Model):
    ...
    title = models.TextField(null=False)
    created_on = models.DateTimeField(default=datetime.now)

I would like to write a Django ORM query where I find all articles that are older than 5 minutes. But I'm not sure how to write such a query. I tried

Article.objects.filter((datetime.now(timezone.utc) - created_on)__gte==300)

But this results in a

SyntaxError: invalid syntax

error.

#python #sql #django

2 Likes4.40 GEEK