I have a model that defines subscription periods by start date and duration (in days):
class SubscriptionProduct(models.Model):
start_date = models.DateField()
duration = models.IntegerField()
I need to be able to filter subscriptions that are currently active, e.g. start_date < now < start_date+duration
I can't find the django way to do it. I can use raw SQL statements that use postgres' DATEADD equivalent of INTERVAL but i'd prefer to use something builtin and non db specific.
I assume ideally i'm looking for a dateadd annotation method. Something like:
SubscriptionProduct.objects.annotate(end_date=DateAdd('start_date','duration').filter(start_date__lt=datetime.now, end_date__gte=datetime.now)