I have a model and UUID as primary key field. UUID id is way too long. I'd like to have it short similar to YouTube.
class Video(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False,
)
Instead of this
UUID('b39596dd-10c9-42c9-91ee-9e45b78ce3c1')
I want to have just this
UUID('b39596dd')
How can I achieve above?
A bit old question, but shortuuidfield may be what you are looking for.
You can use shortuuid library:
from shortuuid.django_fields import ShortUUIDField
id = ShortUUIDField(primary_key=True, length=11, max_length=11)
But you should pay attention to this issue. The smaller the size of the UUID, the higher the probability of Collision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With