我想在每次成功下单后发送电子邮件到特定地址(xxxxx@gmail.com)。我打算捕获被触发的信号并根据这些细节发送电子邮件。我分叉了订单应用程序,这是来自订单模型
from django.db import models
from oscar.apps.order.signals import order_placed
from django.core.mail import send_mail
from oscar.apps.checkout.signals import post_checkout
from oscar.apps.order.abstract_models import AbstractOrder
class Order(AbstractOrder):
def send_order_request(sender, **kwargs):
order = kwargs['instance']
subject = 'New order placed'
send_mail(subject, order, ['xxxxx@gmail.com'])
order_placed.connect(send_order_request, order=self.order,
user=self.user)
from oscar.apps.order.models import *
我目前收到的错误是自我未定义。这是解决这个问题的正确方法吗?
答案 0 :(得分:0)
在使用自我功能之前,必须先创建方法时添加它。就这样:
def send_order_request(self, sender, **kwargs):
...
创建方法时,可以输入名为self的可选参数。