Created
August 13, 2009 08:21
-
-
Save arsatiki/167051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DAY, WEEK, MONTH, YEAR = map(timedelta, (1, 7, 30, 365)) | |
def newer_than(fieldname, delta) | |
# positive values go to past, negative to future. counterintuitive? | |
time = datetime.now() - delta | |
fieldname = fieldname + "__gte" | |
return Q(**fieldname: past) | |
# For more granularity. Probably YAGNI | |
def newer_than2(fieldname, **delta_args) | |
return newer_than(fieldname, timedelta(**delta_args)) | |
# example | |
Blog.objects.filter(newer_than('created', 2*WEEKS)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment