本文整理汇总了Python中treemap.models.MapFeature.has_subclass方法的典型用法代码示例。如果您正苦于以下问题:Python MapFeature.has_subclass方法的具体用法?Python MapFeature.has_subclass怎么用?Python MapFeature.has_subclass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.MapFeature
的用法示例。
在下文中一共展示了MapFeature.has_subclass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detail_link
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import has_subclass [as 别名]
def detail_link(thing):
"""
Get a link to a detail view that can be shown for an
object with this type
For example, a 'treephoto' instance provides a link to
the given tree.
"""
name = thing.__class__.__name__
nameLower = name.lower()
if nameLower in MODEL_DETAILS:
return MODEL_DETAILS[nameLower](thing)
elif MapFeature.has_subclass(name):
return MODEL_DETAILS['mapfeature'](thing)
else:
return None
示例2: safe_get_model_class
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import has_subclass [as 别名]
def safe_get_model_class(model_string):
"""
In a couple of cases we want to be able to convert a string
into a valid django model class. For instance, if we have
'Plot' we want to get the actual class for 'treemap.models.Plot'
in a safe way.
This function returns the class represented by the given model
if it exists in 'treemap.models'
"""
from treemap.models import MapFeature
# All of our models live in 'treemap.models', so
# we can start with that namespace
models_module = __import__('treemap.models')
if hasattr(models_module.models, model_string):
return getattr(models_module.models, model_string)
elif MapFeature.has_subclass(model_string):
return MapFeature.get_subclass(model_string)
else:
raise ValidationError(trans('invalid model type'))