﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11612	Model field 'Default' argument doesn't work as documented	andyortlieb		"According to the docs (I am using 1.0.2 final) at http://docs.djangoproject.com/en/1.0/topics/db/models/

""default
    The default value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.""

But the behavior I'm seeing looks like this:


{{{
>>> from application.models import *
>>> wi,il,ny = OptsState(State='Wisconsin',Abbr='WI'), OptsState(State='Illinois',Abbr='IL'),OptsState(State='New York',Abbr='NY')
>>> wi.uuid
u'02b01c71-f2ae-4d5f-82b1-88660521826a'
>>> il.uuid
u'02b01c71-f2ae-4d5f-82b1-88660521826a'
>>> ny.uuid
u'02b01c71-f2ae-4d5f-82b1-88660521826a'
}}}


The model looks like this:


{{{
class OptsState(models.Model):
    uuid = models.CharField(primary_key=True, editable=False, default=str(uuid.uuid4()))
    State = models.CharField(max_length=16) #Wisconsin, etc...
    Abbr = models.CharField(max_length=16) #wi, etc...
    def __unicode__(self):
        return self.State
}}}

Note, I'm using CharField for simplicity's sake.  I have been using a subclass that returns 'uuid' from db_type for my database server.  I've tried a number of other field classes as well but the result is the same.

It seems to me that it calls uuid.uuid4() ever time a new model is created, but not every time a new object is created.


"		closed	Database layer (models, ORM)	1.0		invalid	default,value,model,field		Unreviewed	0	0	0	0	0	0
