How to filter using an expression in Django
问题 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! 回答1: 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: from django.db.models import DateTimeField, ExpressionWrapper, F Post.objects.annotate( timestamp_minus