Python Forum

Full Version: post_save does not work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to generate a unique key so I created this function but post_save does not work correctly error EmailConfirm is not create
for more info do not hesitate to ask me

from django.db.models.signals import post_save

def user_created(sender,instance,created,*args,**kwargs):
    user=instance
    if created:
        email_confirmed,email_is_created=EmailConfirm.object.get_or_create(user=user)
        if email_is_created:
            short_hash=hashlib.sha1(str(random.random()).encode('utf-8')).hexdigest()[:5]
            #username=user.username
            base,domain=str(user.email).split("@")
            activate_key=hashlib.sha1((short_hash+base).encode('utf-8')).hexdigest()
            email_confirmed.activate_key=activate_key
            email_confirmed.save()
            email_confirmed.activate_user_email()

post_save.connect(user_created, sender=User)
resolved