django signals.post_save() and conditions.

44 views
Skip to first unread message

ysfjwd

unread,
Jan 2, 2013, 4:34:35 AM1/2/13
to django...@googlegroups.com
Is there a way to check a condition on sender model before processing a command. My code

user_logged_in.connect(update_last_login)

def create_activation_code(sender, instance, created, **kwargs):
    print 'The signal is called'
    if created:
        print 'the singal goes to created'
        if not instance.is_active:
            print 'the signal evaluates the active state'
            activation = Activation.objects.create(user=instance)
            activation.get_code()
            activation.save()
        else:
            print 'the signal fails to evaluate active state'

signals.post_save.connect(create_activation_code, sender=User)

can conditions be applied on signals?

//ysfjwd
Reply all
Reply to author
Forward
0 new messages