Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best model field to use for a 128-bit UUID in Django

Tags:

python

django

In Django what model field is best use to store an orderable UUID that comprises of...

[32-bit timestamp high]-[16-bit timestamp mid]-[16-bit timestamp low]-[16 bits random]-[48 bits random]

At the moment I'm using a CharField below is there something better fitted?

id = models.CharField(primary_key=True, max_length=28, unique=True,default=make_key)
like image 298
Prometheus Avatar asked Nov 27 '25 20:11

Prometheus


1 Answers

Django 1.8 introduced UUIDField. It uses UUID class from standard python library in which data is stored in different byte order from what you've presented, but as far as I know python UUID class can present UUID in various formats.

Prior to Django 1.8 you can use some third party package for that.

like image 125
GwynBleidD Avatar answered Nov 29 '25 10:11

GwynBleidD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!