There is Django Order model with property fields automatically calucated. How to do a filter query.
class Order(models.Model):
@property
def expire(self):
return self.created + datetime.timedelta(days=self.days_left())
@property
def days_left(self):
return self.recurrence_period * self._recurrence_unit_days[self.recurrence_unit]
Calculation done to get 1,3,7 datetime days from today
settings.SUBSCRIPTION_EXPIRATION_REMIND = [1, 3, 7]
days = map(lambda x: datetime.date.today() + datetime.timedelta(days=x), settings.SUBSCRIPTION_EXPIRATION_REMIND)
[datetime.date(2015, 7, 28),
datetime.date(2015, 7, 30),
datetime.date(2015, 8, 3)]
How to filter by ORM query
Order.objects.filter(expire__in=days)
Django is throwing error.
FieldError: Cannot resolve keyword 'expire' into field.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…