If I have a model with a couple of fields that inherit from a UserProfile model:
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"))
...
and I use this model to create a model form:
class LeaveRequestForm(ModelForm):
class Meta:
model = LeaveRequest
how can I query for the email url in the User Profile? In this view function, I’m trying to send a notification email on form submit, to the sender(employee) and supervisor:
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('.')
my code for the “recipients” var is invalid but I don’t know how to fix it.
Try
for the employee email and
for the supervisor email.