【发布时间】:2010-11-20 22:29:19
【问题描述】:
我需要创建一个跨站点模板对象,该对象将检查当前时间,如果它在模型中指定的时间范围内,则返回一个字符串,或者在所有其他情况下返回空白。
看起来很简单,但我想知道这里最好的方法是什么?此外,还有一些其他注意事项:
- 字符串应该是可编辑的
- 显示时间的结束时间不应早于开始时间
- 我们需要允许存储多个字符串,但只有一个(或没有)被选为“实时”
作为起点,我会使用模型来定义字符串以及开始和结束时间,如下所示:
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
但是接下来在哪里合并逻辑规则呢?
【问题讨论】:
标签: django datetime django-models django-templates