如果我有一个模型,其中有几个从 UserProfile 模型继承的字段:
class LeaveRequest(models.Model):
employee = models.ForeignKey(UserProfile)
supervisor = models.ForeignKey(UserProfile, related_name='+', blank=False, null=False)
submit_date = models.DateField(("submit date"), default=datetime.date.today)
leave_type = models.CharField(max_length=64, choices=TYPE_CHOICES)
start_date = models.DateField(("start date"))
return_date = models.DateField(("return date"))
...
我使用这个模型来创建一个模型表单:
class LeaveRequestForm(ModelForm):
class Meta:
model = LeaveRequest
如何在用户配置文件中查询电子邮件 url?在此视图功能中,我正在尝试向发件人(员工)和主管发送有关表单提交的通知电子邮件:
def create_request(request):
if request.method == 'POST':
form = LeaveRequestForm(request.POST)
if form.is_valid():
name = form.cleaned_data['employee']
subject = form.cleaned_data['leave_type']
message = form.cleaned_data['notes']
sender = form.cleaned_data['employee']
remoterq = form.save(commit=False)
remoterq.save()
form.save_m2m()
recipients = [user.email for user in remoterq.employee, user.email for user in remoterq.supervisor]
from django.core.mail import send_mail
send_mail(subject, message, 'projects.xxx@google.com', recipients, fail_silently=False)
return HttpResponseRedirect('.')
我的“收件人”变量代码无效,但我不知道如何修复它。