django-signals不发送通知

时间:2013-09-08 20:54:46

标签: django django-signals

我有下一个带信号的模型:

class ParticipantModel(models.Model):
    TYPE_USER = (
        ('O', 'Онлайн трансляция'),
        ('P', 'Персональное присутствие'),
    )

    name = models.CharField( max_length=256, verbose_name='Имя')
    surname = models.CharField(max_length=50, verbose_name='Фамилия')
    position = models.CharField(max_length=50, verbose_name='Должность')
    company = models.CharField(max_length=50, verbose_name='Название компании')
    city = models.CharField(max_length=50, verbose_name='Город')
    email = models.EmailField(verbose_name='Электро почта')
    phone = models.CharField(max_length="50", verbose_name="Телефон")
    phonem = models.CharField(max_length="50", verbose_name="Мобильный телефон")
    www = models.URLField(verbose_name="Сайт")
    tuser = models.CharField(max_length='250', choices=TYPE_USER, verbose_name="Форма вашего участия")

    class Meta:
        verbose_name = ('Участник')
        verbose_name_plural = ('Участники')


def send_marketing(sender, instance, created, **kwargs):
    if created:
        message = "New participant"
        subject = "Updates"
        from_email = 'bakotech.events@gmail.com'
        recipient_list = ('sergey@avetisyan.com.ua')
        send_mail(subject, message, from_email, recipient_list)

    post_save.connect(send_marketing, sender=ParticipantModel)

我的电子邮件后端配置:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'bakotech.events@gmail.com'
EMAIL_HOST_PASSWORD = '********'
EMAIL_PORT = 587

我希望在模型保存到数据库之后,我必须收到有关它的通知的电子邮件

1 个答案:

答案 0 :(得分:2)

在调用post_save之前删除缩进 - 这需要在导入模块时调用,而不是在信号函数内部调用! :)