python - Django Tastypie hidden PK -
i using latest tastypie , have hit snag. need hide pks people can't see service growth. models have uuidfield
. using detail_uri_name
field , gives me uuid instead of id/ pk requests, far.
the problem have when go put
or patch
resource_uri
. thinks new resource doesn't have id , duplicate key errors trying create new record. ideas? here resource.
class userresource(modelresource): class meta: detail_uri_name='uuid' queryset = user.objects.all() resource_name = 'user' always_return_data = true authentication = sessionauthentication() authorization = authorization() excludes=['id', 'password', 'created', 'approved', 'password_reset_code', 'password_reset_datetime'] def prepend_urls(self): return [ url(r'^(?p<resource_name>%s)/(?p<uuid>[\w\.-]+)/$' % self._meta.resource_name, self.wrap_view('dispatch_detail'), name='api_dispatch_detail'), ]
you better off changing model's pk random hash instead. here app that:
a new base class django models, provides them better , random looking primary key 'id' field. solves problem of having predictable, sequentially numbered primary keys django models. use 'randomprimaryidmodel' base class django models. automatically new, random looking ids. generated keys similar know url shorteners. here examples: ada6z uflx1 q68mf zjvsx3 fdxshk vnul0lp
Comments
Post a Comment