2015-05-30 89 views
0

在當前djStripe配置說:djStripe subscriber_has_active_subscription總是假

客戶用戶模型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) 

但對我來說,答案永遠是假的

發生了什麼事?

回答

0

審覈後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的實例,則引發錯誤配置。

我的問題恰恰是,我在呼喚我的個人資料這個功能,那麼這個解決它:

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

UPDATE:我的錯誤是我目前的系統出了問題,你可以在這裏閱讀更多:https://github.com/pydanny/dj-stripe/issues/203#issuecomment-110230688