I'm setting up a journal subscription shopping cart and would like users to be able to order subscriptions based on the distance from the current date.
Each subscription contains 3 issues. I'd like to give people the option to order 1 year starting with the current issue or 1 year starting with the next issue.
My model is fairly simple:
class Subscription(models.Model): start_date = models.DateField(max_length=10) end_date = models.DateField(max_length=10) date = models.DateTimeField(auto_now_add=True, blank=True) def __unicode__(self): return unicode(self.start_date)
Ideally the "Order 1 year starting with current" would look for a
Subscription with a
start_date in the past, but the most recent in the past.
The "Order 1 year starting with next" would return a
Subscription with the
start_date closest to the current date in the future.
How would I implement this kind of logic in the view?