PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 59ms 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
 1# coding: utf-8
 2"""
 332. Callable defaults
 4
 5You can pass callable objects as the ``default`` parameter to a field. When
 6the object is created without an explicit value passed in, Django will call
 7the method to determine the default value.
 8
 9This example uses ``datetime.datetime.now`` as the default for the ``pub_date``
10field.
11"""
12
13from django.db import models
14from datetime import datetime
15
16class Article(models.Model):
17    headline = models.CharField(max_length=100, default='Default headline')
18    pub_date = models.DateTimeField(default=datetime.now)
19
20    def __unicode__(self):
21        return self.headline