djStripe subscriber_has_active_subscription 始终为假

djStripe subscriber_has_active_subscription is always false

关于当前的 djStripe 配置说:

Customer User Model has_active_subscription property

Very useful for working inside of templates or other places where you need to check the subscription status repeatedly. The cached_property decorator caches the result of has_active_subscription for a object instance, optimizing it for reuse.

并要求您添加此代码:

@cached_property
def has_active_subscription(self):
    """Checks if a user has an active subscription."""
    return subscriber_has_active_subscription(self)

但对我来说答案总是错误的

发生什么事了?

查看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)

但这对我仍然不起作用,当我还在阅读时我发现了这个警告:

Helper function to check if a subscriber has an active subscription. Throws improperlyConfigured if the subscriber is an instance of AUTH_USER_MODEL and get_user_model().is_anonymous == True.

我的问题正是这样,我从我的个人资料中调用了这个函数,然后修复它:

@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