I need to create a cross-site template object which will check the current time and return either one string if it's within a time range specified in a model or another or blank in all other cases.
Seems simple, but I wonder what is the best approach here? Also, there are a few other considerations:
- the string should be editable
- the display time should not have an end time before the start time
- we need to allow for multiple strings to be stored, but only one (or none) to be selected as 'live'
As a starting point, I'd use a model to define the string as well as the start and end time, like this:
from datetime import datetime
class dynamicString(models.Model):
start = models.TimeField()
end = models.TimeField()
name = models.CharField(max_length=50, help_text = 'Just for reference, won\'t be displayed on site.')
number = models.CharField(max_length=18, help_text = 'This is the string to be displayed within the above timeframe.')
active = models.BooleanField(help_text = 'Uncheck this to stop string from displaying entierly.')
def __unicode__(self):
return self.name
But where next to incorporate the logic rules?