我想尝试使用dj-stripe库,但是当我尝试覆盖DJSTRIPE_SUBSCRIBER_MODEL时,回调出错了。
以下是模型:
class GroupCompany(models.Model):
owner = models.ForeignKey(Usuario, unique=True, on_delete=models.PROTECT )
def __unicode__(self):
return '%s' % self.owner.get_full_name()
@property
def email(self):
return self.owner.email
这里是settings.py
DJSTRIPE_SUBSCRIBER_MODEL = 'base.GroupCompany'
def account_request_callback(request):
""" Gets an organization instance from the id passed through ``request``"""
return GroupCompany.objects.get(owner=request.user)
DJSTRIPE_SUBSCRIBER_MODEL_REQUEST_CALLBACK = account_request_callback
问题是我无法在设置中导入模型,因为aplications尚未加载,但在dj.stripe的文档中,他们说这是要做的方法!我疯了。
谢谢!
答案 0 :(得分:0)
执行此操作的方法是在回调中导入GroupCompany,以便在执行回调时加载它,如下所示:
def account_request_callback(request):
from ... import GroupCompany
return GroupCompany.objects.get(owner=request.user)
-Alex