-class QuerySetMapper(object, DictMixin):
- def __init__(self, queryset, passthrough=None):
- self.queryset = queryset
- self.passthrough = passthrough
-
- def __getitem__(self, key):
- try:
- value = self.queryset.get(key__exact=key).value
- except ObjectDoesNotExist:
- if self.passthrough is not None:
- return self.passthrough.__getitem__(key)
- raise KeyError
- else:
- if value is not None:
- return value.value
- return value
-
- def keys(self):
- keys = set(self.queryset.values_list('key', flat=True).distinct())
- if self.passthrough is not None:
- keys |= set(self.passthrough.keys())
- return list(keys)
-
-