Hello, another Django send_mail question. Seems like I have problems displaying data in an email that separate form from function. Seems like this is a variable problem.
Edit: I manage to make the client name show up! Now how can to the same thing with invoice. Say that I wanted to display the date, invoice_no, work_orders & contract_info?
#models.py
class Invoice(models.Model):
client = models.ForeignKey(Client)
date = models.DateField()
invoice_no = models.CharField(max_length=16)
work_orders = models.ManyToManyField(Work_Order)
contract_info = models.ForeignKey(Contract_Info)
def __unicode__(self):
return self.invoice_no
#views.py
@login_required
def invoice_mail(request, id=1):
invoices_list = Invoice.objects.filter(pk=id)
client = invoices_list[0].client
t = loader.get_template('registration/email.txt')
c = Context({
'client': client.company,
})
send_mail('Welcome to My Project', t.render(c), '[email protected]', ['[email protected]'], fail_silently=False)
return render_to_response('email.html', locals(), context_instance=RequestContext(request))
Here is my email.txt
Dear {{client}},
And when I send it to my email account I receive this
Dear Currys,