本文整理匯總了Python中polymorphic.models.PolymorphicModel方法的典型用法代碼示例。如果您正苦於以下問題:Python models.PolymorphicModel方法的具體用法?Python models.PolymorphicModel怎麽用?Python models.PolymorphicModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類polymorphic.models
的用法示例。
在下文中一共展示了models.PolymorphicModel方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_save
# 需要導入模塊: from polymorphic import models [as 別名]
# 或者: from polymorphic.models import PolymorphicModel [as 別名]
def handle_save(self, sender, instance, **kwargs):
"""
Given an individual model instance, determine which backends the
update should be sent to & update the object on those backends.
"""
using_backends = self.connection_router.for_write(instance=instance)
for using in using_backends:
try:
# if this signal receives a polymorphic model, return the real class/instance
if isinstance(instance, PolymorphicModel):
sender = instance.get_real_instance_class()
instance = instance.get_real_instance()
index = self.connections[using].get_unified_index(
).get_index(sender)
index.update_object(instance, using=using)
except NotHandled:
# TODO: Maybe log it or let the exception bubble?
pass