获取今天日期位于表中两个日期之间的对象

时间:2017-02-20 11:35:21

标签: python django

我有像这样的django模型

class AthleteSubscription(models.Model):
    user = models.ForeignKey(User, related_name="user_subscription", default='')
    subscription_start = models.DateField(default=datetime.date.today)
    subscription_end = models.DateField(default=datetime.date.today() + timedelta(30))

其中subscription_start是订阅的开始日期,subscription_end是订阅的结束日期。订阅为30天。我想获取当前日期(今天的日期)介于subscription_startsubscription_end之间的记录。我怎么能用django ORM做到这一点。

1 个答案:

答案 0 :(得分:3)

qv = AthleteSubscription.objects.filter(subscription_start__gte=some_date, subscription_end__lte=some_date)