本文整理汇总了Python中subscription.models.Subscription.endDate方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.endDate方法的具体用法?Python Subscription.endDate怎么用?Python Subscription.endDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscription.models.Subscription
的用法示例。
在下文中一共展示了Subscription.endDate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createOrUpdateSubscription
# 需要导入模块: from subscription.models import Subscription [as 别名]
# 或者: from subscription.models.Subscription import endDate [as 别名]
def createOrUpdateSubscription(partyId, partnerId, period):
now = timezone.now()
subscriptionSet = Subscription.objects \
.all() \
.filter(partyId=partyId) \
.filter(partnerId=partnerId)
if len(subscriptionSet) == 0:
subscription = None
else:
subscription = subscriptionSet[0]
transactionType = None
transactionStartDate = None
transactionEndDate = None
if subscription == None:
# case1: new subscription
partyObj = Party.objects.get(partyId=partyId)
partnerObj = Partner.objects.get(partnerId=partnerId)
subscription = Subscription()
subscription.partnerId = partnerObj
subscription.partyId = partyObj
subscription.startDate = now
subscription.endDate = now+datetime.timedelta(days=period)
transactionType = 'Initial'
transactionStartDate = subscription.startDate
transactionEndDate = subscription.endDate
else:
endDate = subscription.endDate
if (endDate<now):
# case2: expired subscription
subscription.endDate = now + datetime.timedelta(days=period)
transactionType = 'Renew'
transactionStartDate = now
transactionEndDate = subscription.endDate
else:
# case3: active subscription
subscription.endDate = endDate + datetime.timedelta(days=period)
transactionType = 'Renew'
transactionStartDate = endDate
transactionEndDate = subscription.endDate
return (subscription, transactionType, transactionStartDate, transactionEndDate)