Skip to content

Instantly share code, notes, and snippets.

@webtweakers
webtweakers / models.py
Last active April 1, 2021 21:28 — forked from parhammmm/models.py
Encrypt and decrypt Django model primary key values (useful for publicly viewable unique identifiers) [python3 version]
# This code is under the MIT license.
# Inspired by this StackOverflow question:
# http://stackoverflow.com/questions/3295405/creating-django-objects-with-a-random-primary-key
# Python 3.x version
import struct
from Crypto.Cipher import DES
from django.db import models
def base36encode(number):