default model field attribute in Django
- by Rosarch
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.