title: default model field attribute in Django
body: <p>I have a Django model:</p>
  
  <pre><code>    @staticmethod
      def getdefault():
          print "getdefault called"
          return cPickle.dumps(set())
  
      _applies_to = models.TextField(db_index=True, default=getdefault)
  </code></pre>
  
  <p>For some reason, <code>getdefault()</code> is never called, even as I construct instances of this model and save them to the database. This seems to contradict the Django <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#default" rel="nofollow">documentation</a>:</p>
  
  <blockquote>
    <p>Field.default</p>
    
    <p>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.</p>
  </blockquote>
  
  <p>Am I doing something wrong?</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>Originally, I had this, but then I switched to the above version to debug:</p>
  
  <pre><code>_applies_to = models.TextField(db_index=True, default=cPickle.dumps(set()))
  </code></pre>
  
  <p>I'm not sure why that wouldn't work.</p>
  
  <p><strong>Update 2</strong>: I'm still having difficulty with this. Here is my model:</p>
  
  <pre><code>class Threshold(models.Model):
      # ...
      _applies_to = models.TextField(db_index=True, default=lambda: cPickle.dumps(set()))
  </code></pre>
  
  <p>And a test:</p>
  
  <pre><code>def setUp(self):
      self.threshold = Threshold() 
  
      self.threshold.save()
  
  def test_default_applies_to(self):
      self.assertEqual(self.threshold._applies_to, cPickle.dumps(set()))  
  </code></pre>
  
  <p>This test fails. I'm not sure why.</p>
  
  <pre><code>FAIL: test_default_applies_to (apps.threshold.tests.ThresholdTest)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "tests.py", line 27, in test_default_applies_to
      self.assertEqual(self.threshold._applies_to, cPickle.dumps(set()))
  AssertionError: 'N.' != 'c__builtin__\nset\np1\n((ltRp2\n.'
  </code></pre>
  
  <p>Why might this be happening? Perhaps I don't understand how <code>default</code> is supposed to work.</p>