本文整理汇总了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])
示例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')
示例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)
示例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)
示例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, [])