def _resolve_template(value, model_instance=None, context=None):
        """Resolves any template references in the given value."""
        if isinstance(value, string_types) and "{" in value:
            if context is None:
                context = Context()
            if model_instance is not None:
                context[model_instance._meta.model_name] = model_instance
            value = Template(value).render(context)
        return value