當前位置: 首頁>>代碼示例>>Python>>正文


Python Category.valid_time方法代碼示例

本文整理匯總了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()
開發者ID:zejn,項目名稱:django_temporal,代碼行數:27,代碼來源:tests.py

示例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()
開發者ID:aarcro,項目名稱:django_temporal,代碼行數:43,代碼來源:tests.py


注:本文中的models.Category.valid_time方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。