class Action(models.Model):
user = models.ForeignKey('auth.User', related_name='actions')
date = models.DateTimeField(editable=False, null=True, blank=True)
以此为例,假设我想过滤不到半小时的特定用户的所有操作?
答案 0 :(得分:2)
您可以这样做:
from datetime import datetime, timedelta
thirty_minutes_ago = datetime.now() - timedelta(minutes=30)
Action.objects.filter(date__gte=thirty_minutes_ago)