本文整理汇总了Python中modelcluster.models.ClusterableModel方法的典型用法代码示例。如果您正苦于以下问题:Python models.ClusterableModel方法的具体用法?Python models.ClusterableModel怎么用?Python models.ClusterableModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modelcluster.models
的用法示例。
在下文中一共展示了models.ClusterableModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: from modelcluster import models [as 别名]
# 或者: from modelcluster.models import ClusterableModel [as 别名]
def check(self, **kwargs):
from modelcluster.models import ClusterableModel
errors = super(ParentalKey, self).check(**kwargs)
# Check that the destination model is a subclass of ClusterableModel.
# If self.rel.to is a string at this point, it means that Django has been unable
# to resolve it as a model name; if so, skip this test so that Django's own
# system checks can report the appropriate error
if isinstance(self.remote_field.model, type) and not issubclass(self.remote_field.model, ClusterableModel):
errors.append(
checks.Error(
'ParentalKey must point to a subclass of ClusterableModel.',
hint='Change {model_name} into a ClusterableModel or use a ForeignKey instead.'.format(
model_name=self.remote_field.model._meta.app_label + '.' + self.remote_field.model.__name__,
),
obj=self,
id='modelcluster.E001',
)
)
# ParentalKeys must have an accessor name (#49)
if self.remote_field.get_accessor_name() == '+':
errors.append(
checks.Error(
"related_name='+' is not allowed on ParentalKey fields",
hint="Either change it to a valid name or remove it",
obj=self,
id='modelcluster.E002',
)
)
return errors