在当前的djStripe配置中,可以这样说:
客户用户模型has_active_subscription属性 对于在模板或其他需要反复检查订阅状态的地方工作非常有用。cached_property装饰器将has_active_subscription的结果缓存为对象实例,并对其进行优化以供重用。
并要求您添加以下代码:
@cached_property
def has_active_subscription(self):
"""Checks if a user has an active subscription."""
return subscriber_has_active_subscription(self)但对我来说,答案总是错误的。
发生什么事了呢?
发布于 2015-05-30 12:52:38
在回顾了djStripe的代码之后,我提供了2种解决方案,您可以在这里阅读:
def user_has_active_subscription(user):
warnings.warn("Deprecated - Use ``subscriber_has_active_subscription`` instead. This method will be removed in dj-stripe 1.0.", DeprecationWarning)
return subscriber_has_active_subscription(user)然后,您必须使用以下方法:
@cached_property
def has_active_subscription(self):
"""Checks if a user has an active subscription."""
return user_has_active_subscription(self)但这对我来说还是没用的,当我还在读的时候,我发现了这样的警告:
函数来检查订阅服务器是否有活动订阅。如果订阅服务器是AUTH_USER_MODEL和get_user_model().is_anonymous == True的实例,则抛出.is_anonymous。
我的问题是,我从我的个人资料中调用这个函数,然后修复它:
@cached_property
def has_active_subscription(self):
"""Checks if a user has an active subscription."""
return user_has_active_subscription(self.user)更新:我的错误是我当前系统的一个问题,你可以在这里读到更多:https://github.com/pydanny/dj-stripe/issues/203#issuecomment-110230688
https://stackoverflow.com/questions/30546431
复制相似问题