Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#11612 closed (invalid)

Model field 'Default' argument doesn't work as documented

Reported by: andyortlieb Owned by:
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords: default, value, model, field
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


According to the docs (I am using 1.0.2 final) at


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
>>> il.uuid
>>> ny.uuid

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.

Change History (2)

comment:1 Changed 11 years ago by Alex Gaynor

Resolution: invalid
Status: newclosed

Please don't use the ticket tracker for support questions. Use the django-users mailiing list or the #django freenode channel.

comment:2 Changed 7 years ago by Anssi Kääriäinen

Component: ORM aggregationDatabase layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top