default model field attribute in Django

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2011-01-13T01:34:23Z Indexed on 2011/01/13 1:54 UTC
Read the original article Hit count: 187

Filed under:
|
|

I have a Django model:

    @staticmethod
    def getdefault():
        print "getdefault called"
        return cPickle.dumps(set())

    _applies_to = models.TextField(db_index=True, default=getdefault)

For some reason, getdefault() is never called, even as I construct instances of this model and save them to the database. This seems to contradict the Django documentation:

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

Am I doing something wrong?

Update:

Originally, I had this, but then I switched to the above version to debug:

_applies_to = models.TextField(db_index=True, default=cPickle.dumps(set()))

I'm not sure why that wouldn't work.

© Stack Overflow or respective owner

Related posts about python

Related posts about django