我正在尝试创建一项服务,用于在过期日期时间少于一周的情况下发送电子邮件。我想做的是只发送一次而不重复。我不知道我应该做什么
楷模:
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)
翻阅古今
相关分类