8

How do I use the UUIDField in my model?

If i do

somefield = UUIDField 

i get:

 UUIDField is not defined.

I do import uuid on top of my models file.

And i have django_extensions in installed apps...

Community
  • 1
  • 1
R0b0tn1k
  • 4,256
  • 14
  • 46
  • 64

1 Answers1

23

A good place to see how to use features of a Django app is in the app's tests.

Here are some example models from django-extension's UUIDField tests that demonstrate how to use the field:

from django.db import models
from django_extensions.db.fields import UUIDField


class TestModel_field(models.Model):
    a = models.IntegerField()
    uuid_field = UUIDField()


class TestModel_pk(models.Model):
    uuid_field = UUIDField(primary_key=True)

Without seeing the whole file, it's hard to tell what's going on. Make sure you import UUIDField from django_extensions.db.fields (like in the above example) and not Python's uuid module.

Ryan Kaskel
  • 4,744
  • 1
  • 19
  • 18