PageRenderTime 31ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/field_defaults/models.py

https://code.google.com/p/mango-py/
Python | 21 lines | 7 code | 3 blank | 11 comment | 0 complexity | 3ee98e48d051bfea37bcb14b0506d723 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # coding: utf-8
  2. """
  3. 32. Callable defaults
  4. You can pass callable objects as the ``default`` parameter to a field. When
  5. the object is created without an explicit value passed in, Django will call
  6. the method to determine the default value.
  7. This example uses ``datetime.datetime.now`` as the default for the ``pub_date``
  8. field.
  9. """
  10. from django.db import models
  11. from datetime import datetime
  12. class Article(models.Model):
  13. headline = models.CharField(max_length=100, default='Default headline')
  14. pub_date = models.DateTimeField(default=datetime.now)
  15. def __unicode__(self):
  16. return self.headline