本文整理汇总了Python中models.Category.valid_time方法的典型用法代码示例。如果您正苦于以下问题:Python Category.valid_time方法的具体用法?Python Category.valid_time怎么用?Python Category.valid_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.valid_time方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import valid_time [as 别名]
def runTest(self):
period = Period(lower=datetime.datetime(1996,10,1), upper=datetime.datetime(1997,1,1))
i = Category(cat=120033, valid_time=period)
i.save()
for bad in [5, 2.0, 'foo', (10, 20)]:
try:
i.valid_time = bad
except TypeError:
pass
else:
self.fail('Should throw a TypeError')
newstr = '[1996-01-01 00:00:00.000000+0000,1996-06-01 00:00:00.000000+0000)'
new = Period(newstr)
for good in (new, newstr):
i.valid_time = good
self.assertEqual(i.valid_time, new)
i.save()
self.assertNotEqual(i.pk, None)
self.assertEqual(new, Category.objects.get(pk=i.pk).valid_time)
i.delete()
示例2: runTest
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import valid_time [as 别名]
def runTest(self):
"Test period field options - unique types (sequenced, current and nonsequenced)"
period = Period(start=datetime.datetime(1996,10,1), end=datetime.datetime(1997,1,1))
i = Category(cat=120033, valid_time=period)
# Test overlapping periods - sequenced unique.
i.valid_time = '[1996-05-01 00:00:00.000000+0000,1996-07-01 00:00:00.000000+0000)'
try:
i.save()
except IntegrityError:
connection.connection.rollback()
else:
self.fail('Should throw an IntegrityError')
# Test current unique.
i.valid_time = '[1996-05-01 00:00:00.000000+0000,9999-12-31 23:59:59.999999+0000)'
try:
i.save()
except IntegrityError:
connection.connection.rollback()
else:
self.fail('Should throw an IntegrityError')
# Test nonsequenced unique.
i1 = CategoryToo(cat=120033, valid_time=period)
i1.save()
i2 = CategoryToo(cat=120033, valid_time=period)
try:
i2.save()
except IntegrityError:
connection.connection.rollback()
else:
self.fail('Should throw and IntegrityError')
i2.cat = 100100
# Saves okay.
i2.save()
i1.delete()
i2.delete()