parts/django/tests/modeltests/field_defaults/models.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 # coding: utf-8
       
     2 """
       
     3 32. Callable defaults
       
     4 
       
     5 You can pass callable objects as the ``default`` parameter to a field. When
       
     6 the object is created without an explicit value passed in, Django will call
       
     7 the method to determine the default value.
       
     8 
       
     9 This example uses ``datetime.datetime.now`` as the default for the ``pub_date``
       
    10 field.
       
    11 """
       
    12 
       
    13 from django.db import models
       
    14 from datetime import datetime
       
    15 
       
    16 class 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