gpt4 book ai didi

python - django 发送电子邮件收件人列表

转载 作者:太空宇宙 更新时间:2023-11-03 21:31:13 25 4
gpt4 key购买 nike

我需要获取在数据库中注册的电子邮件并将其发送到该已注册的电子邮件,但我不能。如果我手动输入电子邮件,它会毫无问题地发送,但我需要它来获取在 Pessoa 中注册的电子邮件,以便在 MovRotativo 中使用,以便在完成后立即发送付款

错误“/sistema/mov-rot-novo/处的类型错误“Pessoa”类型的对象没有 len()"

模型.py

from django.db import models
from django.core.mail import send_mail
import math
PAGO_CHOICES = (
('Não', 'Não Pago'),
('Sim', 'Pago')
)

class Pessoa(models.Model):
nome = models.CharField(max_length=50, blank=False)
email = models.EmailField(blank=False)
cpf = models.CharField(max_length=11, unique=True, blank=False)
endereco = models.CharField(max_length=50)
numero = models.CharField(max_length=10)
bairro = models.CharField(max_length=30)
telefone = models.CharField(max_length=20, blank=False)
cidade = models.CharField(max_length=20)
estado = models.CharField(max_length=2, choices=STATE_CHOICES)

def __str__(self):
return str(self.nome) + ' - ' + str(self.email)

class MovRotativo(models.Model):
checkin = models.DateTimeField(auto_now=False, blank=False, null=False,)
checkout = models.DateTimeField(auto_now=False, null=True, blank=True)
email = models.ForeignKey(Pessoa, on_delete=models.CASCADE, blank=False)
valor_hora = models.DecimalField(
max_digits=5, decimal_places=2, null=False, blank=False)
veiculo = models.ForeignKey(
Veiculo, on_delete=models.CASCADE, null=False, blank=False)
pago = models.CharField(max_length=15, choices=PAGO_CHOICES)

def send_email(self):
if self.pago == 'Sim':

send_mail(
'Comprovante pagamento Estacione Aqui 24 Horas',
'Here is the message.',
'estacioneaqui24@gmail.com',
recipient_list=[self.email],
fail_silently=False,
)

最佳答案

MovRotativo 中,email 不是 EmailField 而是类 Pessoa 的实例。您需要来自 Pessoa电子邮件,即 email.email:

recipient_list=[self.email.email],

关于python - django 发送电子邮件收件人列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53502160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com