Encrypted pk in django

Django -- Posted on Dec. 28, 2017

Encrypted pk in django

              
                import hashlib
from django.db import models

class Encryptedhash(models.Model):
    encrypted_pk = models.CharField(blank=True, max_length=255)

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        m = hashlib.sha224("{}".format(self.pk).encode('utf-8')).hexdigest()
        self.encrypted_pk = m
        super().save(*args, **kwargs)
                  
   
            

Related Posts