我正在使用最新的Tastypie并且遇到了障碍。我需要隐藏PK,以便人们看不到服务增长。所有模型都有background:url();
。我正在使用UUIDField
字段,它为我提供了uuid而不是ID / PK,所以到目前为止一切都很好。
我遇到的问题是当我detail_uri_name
或PUT
转到PATCH
时。它认为这是一个新的资源,因为没有ID,因此我在尝试创建新记录时遇到重复的密钥错误。有任何想法吗?这是我的资源。
resource_uri
答案 0 :(得分:0)
最好将模型的pk更改为随机哈希。 Here is an app就是这样做的:
A new base class for Django models, which provides them with a better
and random looking primary key for the 'id' field.
This solves the problem of having predictable, sequentially numbered
primary keys for Django models.
Just use 'RandomPrimaryIdModel' as base class for your Django models.
They will then automatically get those new, random looking IDs.
The generated keys look similar to what you know from URL shorteners.
Here are some examples:
Ada6z
UFLX1
Q68mf
zjvsx3
fDXshK
VNuL0Lp