Question

i have next model with signal :

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)

My emailbackend configuration :

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

I wants that after model save to database, i have to receive email with notification about it

Was it helpful?

Solution

Remove the indentation before the call to post_save - this needs to be called when the module is imported, not inside the signal function! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top