Prometheus
Prometheus

Reputation: 33655

Best model field to use for a 128-bit UUID in 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)

Upvotes: 3

Views: 685

Answers (1)

GwynBleidD
GwynBleidD

Reputation: 20569

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.

Upvotes: 3

Related Questions