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


Python ModelBase.slug方法代码示例

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


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

示例1: test_unique_slugs

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import slug [as 别名]
    def test_unique_slugs(self):
        # create 2 sites
        site_1 = Site(id=201, domain="site1.example.com")
        site_1.save()
        site_2 = Site(id=202, domain="site2.example.com")
        site_2.save()

        # Create an object for site 1
        obj_1 = ModelBase(title='object for site 1')
        obj_1.save()
        obj_1.sites.add(site_1)
        obj_1.slug = 'generic_slug'
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title='object for site 2')
        obj_2.save()
        obj_2.sites.add(site_2)
        obj_2.slug = 'generic_slug'
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.sites.add(site_1)
            obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = 'generic_slug_2'
        obj_2.sites.add(site_1)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(RuntimeError):
            obj_2.slug = 'generic_slug'
            obj_2.save()
开发者ID:,项目名称:,代码行数:37,代码来源:

示例2: test_unique_slugs

# 需要导入模块: from jmbo.models import ModelBase [as 别名]
# 或者: from jmbo.models.ModelBase import slug [as 别名]
    def test_unique_slugs(self):
        obj_1 = ModelBase(title="object for site 1")
        obj_1.save()
        obj_1.sites.add(self.web_site)
        obj_1.slug = "generic_slug"
        obj_1.save()

        # Create an object for site 2
        obj_2 = ModelBase(title="object for site 2")
        obj_2.save()
        obj_2.sites.add(self.mobile_site)
        obj_2.slug = "generic_slug"
        obj_2.save()

        # Trying to add site_1 should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.sites.add(self.web_site)
                obj_2.save()

        # When the slugs differ, you can add site_1.
        obj_2.slug = "generic_slug_2"
        obj_2.sites.add(self.web_site)
        obj_2.save()

        # Trying to change the slug to an existing one should raise an error.
        with self.assertRaises(IntegrityError):
            with transaction.atomic():
                obj_2.slug = "generic_slug"
                obj_2.save()
开发者ID:praekelt,项目名称:jmbo,代码行数:32,代码来源:test_modelbase.py


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