本文整理汇总了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