def value(self, obj):
        '''
        Computes the value of this field to update the index.
        :param obj: object instance, as a dictionary or as a model instance.
        '''
        if self.template_name:
            t = loader.select_template([self.template_name])
            return t.render(Context({'object': obj}))

        if self.eval_func:
            try:
                return eval(self.eval_func)
            except Exception as e:
                raise type(e)('Could not compute value of {} field (eval_as=`{}`): {}.'.format(unicode(self), self.eval_func, unicode(e)))

        elif self.model_attr:
            if isinstance(obj, dict):
                return obj[self.model_attr]
            current_obj = getattr(obj, self.model_attr)

            if callable(current_obj):
                return current_obj()
            else:
                return current_obj

        else:
            raise KeyError('{0} gets its value via a model attribute, an eval function, a template, or is prepared in a method '
                           'call but none of `model_attr`, `eval_as,` `template,` `prepare_{0}` is provided.'.format(unicode(self)))
Computes the value of this field to update the index.
        :param obj: object instance, as a dictionary or as a model instance.