Created
January 29, 2011 15:49
-
-
Save orb/801935 to your computer and use it in GitHub Desktop.
An automatic UUID Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django_extensions.db.fields import UUIDField | |
class AutoUUIDField(UUIDField): | |
def contribute_to_class(self, cls, name): | |
assert not cls._meta.has_auto_field, "A model can't have more than one AutoField." | |
super(UUIDField, self).contribute_to_class(cls, name) | |
cls._meta.has_auto_field = True | |
cls._meta.auto_field = self | |
class MyModel(models.Model): | |
id = AutoUUIDField(primary_key=True) | |
# etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment