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


Python signals.post_init方法代码示例

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


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

示例1: test_model_pre_init_and_post_init

# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_init [as 别名]
def test_model_pre_init_and_post_init(self):
        data = []

        def pre_init_callback(sender, args, **kwargs):
            data.append(kwargs['kwargs'])
        signals.pre_init.connect(pre_init_callback)

        def post_init_callback(sender, instance, **kwargs):
            data.append(instance)
        signals.post_init.connect(post_init_callback)

        p1 = Person(first_name="John", last_name="Doe")
        self.assertEqual(data, [{}, p1]) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例2: test_invalid_sender_model_name

# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_init [as 别名]
def test_invalid_sender_model_name(self):
        msg = "Invalid model reference 'invalid'. String model references must be of the form 'app_label.ModelName'."
        with self.assertRaisesMessage(ValueError, msg):
            signals.post_init.connect(self.receiver, sender='invalid') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py

示例3: test_already_loaded_model

# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_init [as 别名]
def test_already_loaded_model(self):
        signals.post_init.connect(
            self.receiver, sender='signals.Book', weak=False
        )
        try:
            instance = Book()
            self.assertEqual(self.received, [{
                'signal': signals.post_init,
                'sender': Book,
                'instance': instance
            }])
        finally:
            signals.post_init.disconnect(self.receiver, sender=Book) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例4: test_not_loaded_model

# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_init [as 别名]
def test_not_loaded_model(self, apps):
        signals.post_init.connect(
            self.receiver, sender='signals.Created', weak=False, apps=apps
        )

        try:
            class Created(models.Model):
                pass

            instance = Created()
            self.assertEqual(self.received, [{
                'signal': signals.post_init, 'sender': Created, 'instance': instance
            }])
        finally:
            signals.post_init.disconnect(self.receiver, sender=Created) 
开发者ID:nesdis,项目名称:djongo,代码行数:17,代码来源:tests.py

示例5: test_disconnect

# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_init [as 别名]
def test_disconnect(self, apps):
        received = []

        def receiver(**kwargs):
            received.append(kwargs)

        signals.post_init.connect(receiver, sender='signals.Created', apps=apps)
        signals.post_init.disconnect(receiver, sender='signals.Created', apps=apps)

        class Created(models.Model):
            pass

        Created()
        self.assertEqual(received, []) 
开发者ID:nesdis,项目名称:djongo,代码行数:16,代码来源:tests.py


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