Creating django objects with a random primary key

前端 未结 6 1528
面向向阳花
面向向阳花 2021-02-08 12:08

I\'m working with an API that wants me to generate opaque \"reference IDs\" for transactions with their API, in other words, unique references that users can\'t guess or infer i

6条回答
  •  庸人自扰
    2021-02-08 12:27

    Why not just encrypt the normal sequential ids instead? To someone who doesn't know the encryption key, the ids will seem just as random. You can write a wrapper that automatically decrypts the ID on the way to the DB, and encrypts it on the way from the DB.

提交回复
热议问题