I want to generate UUID for my models, and officially, what I did is exactly as what the official doc demonstrates.
import uuid
from django.db import models
class MyUUIDModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
However, I also find django_extension
to do similiar job for me. I don't know what's the difference between, but I do want to unify my code for better production purpose. Any help, thanks.
Django did not include a UUIDField
until version 1.8, which is why it was created as an "extension" by the Django Extensions maintainers. Now that Django includes UUIDField
natively the Django Extensions maintainers are sunsetting their version, but are continuing to maintain their UUIDField
for people using Django < 1.8 until Django 1.7 is no longer supported per the docs.
If you are using Django >= 1.8 you should be using django.db.models.UUIDField
.