Reputation:
I know this question is the one someone already asked but I really don't understand when I should use UUID. I just started to try to bulid REST API in Django. And I've read we should use UUID but I don't understand how to use it.
For example, I currently use id
to refer to a specific object in api views as I write in usual views.py
. Is it what I should not do? If so, how users can refer to a object using UUID
? When is it used?
@api_view(['GET', 'PUT', 'DELETE'])
def specific_entry(request, pk, format=None):
entry = get_object_or_404(Entry, id=pk)
...
Upvotes: 1
Views: 1374
Reputation: 5669
It's up to you. UUID is such complex and unique, not auto incremented field that is used instead of common Id field. So if you want to use it you can just specify in your model:
import uuid
id = models.UUIDField(default=uuid.uuid4, primary_key=true)
But it's up to you, you can continue using AutoField for id.
In order to compare you can read there
Upvotes: 2