<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>David Cramer's Blog - Latest Comments in Improved UUIDField in Django</title><link>http://davidcramer.disqus.com/</link><description></description><atom:link href="https://davidcramer.disqus.com/thread_62/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 22 Nov 2010 16:17:39 -0000</lastBuildDate><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-100842547</link><description>&lt;p&gt;How do you get this to work as the primary_key on an admin inline?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Your Name</dc:creator><pubDate>Mon, 22 Nov 2010 16:17:39 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-49075446</link><description>&lt;p&gt;Thanks for the code.  I have a question about getting an object based on the guid field.  Here is what I have&lt;/p&gt;&lt;p&gt;	from myproj.myapp.models import mymodel&lt;br&gt;	import uuid&lt;br&gt;	u = uuid.UUID('eb7e2cc4-db24-4c3d-b8f6-73bed6468135')&lt;br&gt;	w = mymodel.objects.get(guid=u)&lt;/p&gt;&lt;p&gt;This results in a DoesNotExist exception.&lt;/p&gt;&lt;p&gt;If I change the get_db_prep_value function of &lt;a href="http://UUIDField.py" rel="nofollow noopener" target="_blank" title="UUIDField.py"&gt;UUIDField.py&lt;/a&gt; to the following, it works:&lt;/p&gt;&lt;p&gt;    def get_db_prep_value(self, value):&lt;br&gt;        if not value: return&lt;br&gt;        assert(isinstance(value, uuid.UUID))&lt;br&gt;        #return unicode(value)&lt;br&gt;        return value.hex&lt;/p&gt;&lt;p&gt;Did I miss something?  Is there another way to do this?  Thanks.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">chris</dc:creator><pubDate>Sat, 08 May 2010 06:38:10 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-45904720</link><description>&lt;p&gt;Removed features, and updated for 1.2 and South: &lt;a href="http://gist.github.com/374662" rel="nofollow noopener" target="_blank" title="http://gist.github.com/374662"&gt;http://gist.github.com/374662&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andrew Badr</dc:creator><pubDate>Wed, 21 Apr 2010 20:58:51 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-45761059</link><description>&lt;p&gt;I'm also using 'uuid', and have the following methods for Django 1.2 support:&lt;br&gt;&lt;br&gt;&lt;/p&gt;&lt;pre&gt;&lt;br&gt;    def get_prep_value(self, value):                                                               &lt;br&gt;        if not value:                                                                              &lt;br&gt;            return&lt;br&gt;        assert(isinstance(value, uuid.UUID))                                                       &lt;br&gt;        return value.hex                                                                           &lt;br&gt;    &lt;br&gt;    def get_prep_lookup(self, lookup_type, value):                                                 &lt;br&gt;        if lookup_type == 'exact':                                                                 &lt;br&gt;            return value.hex&lt;br&gt;        elif lookup_type == 'in':&lt;br&gt;            return [u.hex for u in value]&lt;br&gt;        raise ValueError, "UUIDField does not support '%s' queries" % lookup_type  &lt;br&gt;&lt;br&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;edit: see my other post for full solution&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andrew Badr</dc:creator><pubDate>Tue, 20 Apr 2010 22:12:05 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940797</link><description>&lt;p&gt;Thanks for sharing - this code works well for me!  I'm also experimenting with just using a regular CharField and auto-populating the value using a post_init signal handler.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Underhill</dc:creator><pubDate>Thu, 28 Jan 2010 15:06:23 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940796</link><description>&lt;p&gt;I'm using the following for Postgres 8.2.&lt;/p&gt;&lt;p&gt;    def db_type(self):&lt;br&gt;        return 'character varying(32)'&lt;/p&gt;&lt;p&gt;    def get_db_prep_value(self, value):&lt;br&gt;        if not value: return&lt;br&gt;        if not isinstance(value, uuid.UUID):&lt;br&gt;            value = uuid.UUID(value)&lt;br&gt;        return value.hex #unicode(value)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">EdMenendez</dc:creator><pubDate>Thu, 25 Jun 2009 20:54:29 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940795</link><description>&lt;p&gt;I originally started out using UUID as primary keys on my old project. I had some trouble   with uuid imports in Python 2.5&lt;/p&gt;&lt;p&gt;I seem to recall that if you for some reason try to import uuid in &lt;a href="http://settings.py" rel="nofollow noopener" target="_blank" title="settings.py"&gt;settings.py&lt;/a&gt; python will silently crash.&lt;/p&gt;&lt;p&gt;Did you have any trouble like that?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">HenrikV</dc:creator><pubDate>Tue, 24 Mar 2009 19:08:56 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940794</link><description>&lt;p&gt;Ah, sorry, I need varchar(length) on Postgres... but it supports uuid anyway, so I'm using ---&lt;/p&gt;&lt;p&gt;    def db_type(self):&lt;br&gt;        return 'uuid'&lt;/p&gt;&lt;p&gt;Although it seems (for me, at least) that get_db_prep_value assumes it's dealing with a uuid.UUID, when in the admin change view it's a unicode (and postgresql and other DBs seemingly want a 36 char string anyway...) so I'm using the following,&lt;/p&gt;&lt;p&gt;    def get_db_prep_value(self, value):&lt;br&gt;        if not value: return&lt;br&gt;        print type(value)&lt;br&gt;        if isinstance(value, uuid.UUID):&lt;br&gt;            return unicode(value)&lt;br&gt;        return value&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joe</dc:creator><pubDate>Wed, 11 Mar 2009 23:57:19 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940793</link><description>&lt;p&gt;Yeah, for some reason my __init__ doesn't seem to be called in trunk.&lt;/p&gt;&lt;p&gt;In other words with,&lt;/p&gt;&lt;p&gt;class MyModel(models.Model):&lt;br&gt;    uuid = UUIDField(primary_key=True, db_index=True, auto=True)&lt;/p&gt;&lt;p&gt;I get a character(1) in my DB (postgresql) and thus everything fails... so weird.  I can even import the class and UUIDField() with a 1/0 in the init and nothing happens?  I assume this has to do with the metaclass or something?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joe</dc:creator><pubDate>Wed, 11 Mar 2009 22:52:43 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940792</link><description>&lt;p&gt;Sorry the original code has been fixed.&lt;/p&gt;&lt;p&gt;However, there seems to be an issue in Django where it's not quite passing in UUID instances everywhere. I'm currently looking into why.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Cramer</dc:creator><pubDate>Tue, 10 Mar 2009 15:01:49 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940791</link><description>&lt;p&gt;What is the variable "name" here (undefined)?&lt;/p&gt;&lt;p&gt;elif version in (3, 5):&lt;br&gt;    self.namespace, &lt;a href="http://self.name" rel="nofollow noopener" target="_blank" title="self.name"&gt;self.name&lt;/a&gt; = namespace, name&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joe</dc:creator><pubDate>Sun, 08 Mar 2009 12:42:38 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940790</link><description>&lt;p&gt;Any patched for useful improvements to the UUIDField in django-extensions would be much appreciated :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">trbs</dc:creator><pubDate>Tue, 03 Mar 2009 05:15:18 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940788</link><description>&lt;p&gt;Very nice.  Do you know how this compares to the UUIDField in django extensions?&lt;/p&gt;&lt;p&gt;&lt;a href="http://code.google.com/p/django-command-extensions/source/browse/trunk/django_extensions/db/fields/__init__.py" rel="nofollow noopener" target="_blank" title="http://code.google.com/p/django-command-extensions/source/browse/trunk/django_extensions/db/fields/__init__.py"&gt;http://code.google.com/p/dj...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">skabber</dc:creator><pubDate>Mon, 02 Mar 2009 13:36:31 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940786</link><description>&lt;p&gt;Careful, the uuid module is not in 2.4 or below.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Brantley Harris</dc:creator><pubDate>Mon, 02 Mar 2009 11:24:58 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940783</link><description>&lt;p&gt;This one seems useful, thanks!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">at9t</dc:creator><pubDate>Sun, 01 Mar 2009 08:52:57 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940782</link><description>&lt;p&gt;ah, good point.  I was thinking in terms of using a UUIDField as a model's PK, without considering FK scenarios.  Thanks again!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Josh</dc:creator><pubDate>Sat, 28 Feb 2009 20:34:55 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940781</link><description>&lt;p&gt;No because it could just be a ForeignKey reference.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Cramer</dc:creator><pubDate>Sat, 28 Feb 2009 20:22:12 -0000</pubDate></item><item><title>Re: Improved UUIDField in Django</title><link>http://cramer.io//420/improved-uuidfield-in-django.html#comment-38940780</link><description>&lt;p&gt;Interesting snippet!! Thanks for sharing.&lt;/p&gt;&lt;p&gt;One question: shouldn't "kwargs['unique'] = True" be outside of the "if &lt;a href="http://self.auto" rel="nofollow noopener" target="_blank" title="self.auto"&gt;self.auto&lt;/a&gt;:" block?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Josh</dc:creator><pubDate>Sat, 28 Feb 2009 20:18:16 -0000</pubDate></item></channel></rss>