當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。