def lookup(self, instance=None, content_type=None, selectors=None):
if instance is not None and content_type is None:
content_type = ContentType.objects.get_for_model(instance)
if selectors is None and instance is not None:
selectors = self._get_selectors(instance, content_type)
selectors = tuple(selectors)
if any(s is None for s in selectors):
return None
# Look for schema list in cache, keyed by content type and
# selector list.
key = schema_cache_key(content_type, selectors)
cached = caches['jsonattrs'].get(key)
if cached is not None:
return cached
# Not in cache: build schema list using increasing selector
# sequences.
base_schemas = self.filter(content_type=content_type)
schemas = []
for i in range(len(selectors) + 1):
schemas += list(base_schemas.filter(selectors=selectors[:i]))
caches['jsonattrs'].set(key, schemas)
return schemas
评论列表
文章目录