I'd like to filter that implements this "pseudocode":
Post.objects.filter(Post.timestamp + Post.duration > datetime.datetime.now())
I also would like to wrap this in a Django management command.
Any help would be great!
I'd like to filter that implements this "pseudocode":
Post.objects.filter(Post.timestamp + Post.duration > datetime.datetime.now())
I also would like to wrap this in a Django management command.
Any help would be great!
Filter
Not sure how your fields look but here's a hint:
Let's compose an F expression like this
F('timestamp') - F('duration')
, and annotate our query with it:Now you can filter with that annotated field
ref: https://docs.djangoproject.com/en/1.9/topics/db/queries/#using-f-expressions-in-filters
ref: https://docs.djangoproject.com/es/1.9/ref/models/expressions/#using-f-with-annotations
ref: https://docs.djangoproject.com/es/1.9/topics/db/aggregation/#filtering-on-annotations
Management Command
Just put the code in the
handle()
method of the commandMore details: https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/