当前位置: 首页>>代码示例>>Python>>正文


Python Book.published方法代码示例

本文整理汇总了Python中models.Book.published方法的典型用法代码示例。如果您正苦于以下问题:Python Book.published方法的具体用法?Python Book.published怎么用?Python Book.published使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Book的用法示例。


在下文中一共展示了Book.published方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_default_creation

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import published [as 别名]
    def test_default_creation(self):
        "Objects created on the default database don't leak onto other databases"
        # Create a book on the default database using create()
        Book.objects.create(title="Pro Django",
                            published=datetime.date(2008, 12, 16))

        # Create a book on the default database using a save
        dive = Book()
        dive.title="Dive into Python"
        dive.published = datetime.date(2009, 5, 4)
        dive.save()

        # Check that book exists on the default database, but not on other database
        try:
            Book.objects.get(title="Pro Django")
            Book.objects.using('default').get(title="Pro Django")
        except Book.DoesNotExist:
            self.fail('"Dive Into Python" should exist on default database')

        self.assertRaises(Book.DoesNotExist,
            Book.objects.using('other').get,
            title="Pro Django"
        )

        try:
            Book.objects.get(title="Dive into Python")
            Book.objects.using('default').get(title="Dive into Python")
        except Book.DoesNotExist:
            self.fail('"Dive into Python" should exist on default database')

        self.assertRaises(Book.DoesNotExist,
            Book.objects.using('other').get,
            title="Dive into Python"
        )
开发者ID:arnav,项目名称:django,代码行数:36,代码来源:tests.py

示例2: test_attribute_error_save

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import published [as 别名]
 def test_attribute_error_save(self):
     "Check that the AttributeError from AttributeErrorRouter bubbles up"
     dive = Book()
     dive.title="Dive into Python"
     dive.published = datetime.date(2009, 5, 4)
     self.assertRaises(AttributeError, dive.save)
开发者ID:0xmilk,项目名称:mongodb-engine,代码行数:8,代码来源:tests.py


注:本文中的models.Book.published方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。