Skip to content

Commit

Permalink
Ticket 50: Added proposed fix for UUIDField to allow it to be fixed a…
Browse files Browse the repository at this point in the history
…s primary_key
  • Loading branch information
trbs committed Nov 25, 2010
1 parent 117d35d commit 22b5af8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion django_extensions/db/fields/__init__.py
Expand Up @@ -211,6 +211,15 @@ def __init__(self, verbose_name=None, name=None, auto=True, version=1, node=None
def get_internal_type(self):
return CharField.__name__

def contribute_to_class(self, cls, name):
if self.primary_key:
assert not cls._meta.has_auto_field, "A model can't have more than one AutoField: %s %s %s; have %s" % (self,cls,name,cls._meta.auto_field)
super(UUIDField, self).contribute_to_class(cls, name)
cls._meta.has_auto_field = True
cls._meta.auto_field = self
else:
super(UUIDField, self).contribute_to_class(cls, name)

def create_uuid(self):
if not self.version or self.version==4:
return uuid.uuid4()
Expand Down Expand Up @@ -244,4 +253,4 @@ def south_field_triple(self):
field_class = "django.db.models.fields.CharField"
args, kwargs = introspector(self)
# That's our definition!
return (field_class, args, kwargs)
return (field_class, args, kwargs)

0 comments on commit 22b5af8

Please sign in to comment.