本文整理匯總了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