您好,我正在尝试从我的 mysql 数据库中显示工作订单以显示在电子邮件中。但是有一个问题,因为 work_orders 是我的 Class Invoice manytomany 字段的一部分。这给了我这个错误。
'ManyRelatedManager' object has no attribute 'description'
我不确定问题是什么。这是我的应用程序的某些部分,可能会有所帮助。
#views.py
@login_required
def invoice_mail(request, id=1):
invoices_list = Invoice.objects.filter(pk=id)
invoice = get_object_or_404(Invoice, pk=id)
client = invoices_list[0].client
invoice_no = invoices_list[0].invoice_no
date = invoices_list[0].date
work_orders = invoices_list[0].work_orders
t = loader.get_template('registration/email.txt')
c = Context({
'client': client.company,
'address':client.address,
'city': client.city,
'postcode': client.postcode,
'email': client.email,
'date': date,
'invoice_no': invoice_no,
'work_orders': work_orders.description,
})
send_mail('Welcome to My Project', t.render(c), 'jess@example.com', ['tom@example.com'], fail_silently=False)
return render_to_response('sent_email.html', locals(), context_instance=RequestContext(request))
email.txt
INVOICE
Bill to: INVOICE # {{invoice_no}}
{{client}} DATE: {{date}}
{{address}}
{{city}}
{{postcode}}
{{email}}
quantity item Description
{{work_orders.description}}