我正在尝试创建一项服务,用于在过期日期时间少于一周的情况下发送电子邮件。我想做的是只发送一次而不重复。我不知道我应该做什么楷模:class License(models.Model): PACKAGE_CHOISES = ( ('Production', 'Production'), ('Evaluation', 'Evaluation'), ) LICENSE_CHOISES = ( ('js', 'Javascript_sdk'), ('ios', 'Ios_sdk'), ('android', 'Android_sdk'), ) client = models.ForeignKey('Client', on_delete=models.CASCADE) package = models.CharField(max_length=15, choices=PACKAGE_CHOISES, blank=True, null=True) license_type = models.CharField(max_length=15, choices=LICENSE_CHOISES, blank=True, null=True) created_datetime = models.DateTimeField(auto_now=True) expiration_datetime = models.DateTimeField(default=get_default_license_expiration)这是我正在尝试构建的服务:def process_licenses(): client = Client.objects.all() licesens = License.objects.all() clients_name = [] hoje = datetime.today() - timedelta(days=7) for date in licesens: if hoje >= date.expiration_datetime: clients_name.append(date.client) for name in clients_name: if name in client: email = EmailMessage( 'Test', 'hi', settings.EMAIL_HOST_USER, [name.admin_poc], ) email.fail_silently=False email.send() time.sleep(30)
1 回答
翻阅古今
TA贡献1780条经验 获得超5个赞
在许可证模型中添加此列
is_send = models.BooleanField(default=False, blank=True, null=True)for date in licesens: if hoje >= date.expiration_datetime and is_send is False: clients_name.append(date.client) license_instance = License.objects.get(pk=date.pk) license_instance.is_send = True license_instance.save()
添加回答
举报
0/150
提交
取消