Задать вопрос

Тел: +7 965 3737 888

487

Просмотров

0

Ответов

Execute a signal once

<p>Decorates signals for executing only one time</p>
<p>Exemple usage :</p>
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.contrib.auth.models import User

@one
def user_welcome(sender, instance, created, **kwargs):
    # Send a welcome email
    if created == True and isinstance(instance, User):
        instance.message_set.create(message=_(u"Ho, Welcome %s!" % instance))
        subject, from_email, to = 'Welcome !', 'from@example.com', instance.email
        text_content = render_to_string('mail/welcome.html', { 'user': instance })
        msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
        msg.send()

Вопрос полезен? Да0/Нет0
file_4399.py(1.3Кб)
None