Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: How do I use UUIDField from django-extensions

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...

like image 782
R0b0tn1k Avatar asked Jan 07 '12 21:01

R0b0tn1k


1 Answers

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.

like image 100
Ryan Kaskel Avatar answered Nov 06 '22 20:11

Ryan Kaskel