Module Expr Str ImportFrom alias ImportFrom alias ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad ClassDef bases body Assign NameStore TupleLoad Str decorator_list FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list decorator_list Assign NameStore Dict Str Str If CompareEq AttributeLoad NameLoad attr Str body AugAssignAdd SubscriptStore NameLoad Index Str Str
N/A N/A 
This is a basic model to test saving and loading boolean and date-related
types, which in the past were problematic for some database backends.
 django.db models django.conf settings Donut N/A N/A models Model N/A N/A name N/A N/A models CharField max_length 100 N/A is_frosted N/A N/A models BooleanField default False N/A has_sprinkles N/A N/A models NullBooleanField N/A baked_date N/A N/A models DateField null True N/A baked_time N/A N/A models TimeField null True N/A consumed_at N/A N/A models DateTimeField null True Meta N/A N/A N/A ordering N/A consumed_at N/A __str__ N/A N/A self N/A N/A N/A N/A self name N/A N/A N/A __test__ N/A API_TESTS 
# No donuts are in the system yet.
>>> Donut.objects.all()
[]

>>> d = Donut(name='Apple Fritter')

# Ensure we're getting True and False, not 0 and 1
>>> d.is_frosted
False
>>> d.has_sprinkles
>>> d.has_sprinkles = True
>>> d.has_sprinkles == True
True
>>> d.save()
>>> d2 = Donut.objects.all()[0]
>>> d2
<Donut: Apple Fritter>
>>> d2.is_frosted == False
True
>>> d2.has_sprinkles == True
True

>>> import datetime
>>> d2.baked_date = datetime.date(year=1938, month=6, day=4)
>>> d2.baked_time = datetime.time(hour=5, minute=30)
>>> d2.consumed_at = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)
>>> d2.save()

>>> d3 = Donut.objects.all()[0]
>>> d3.baked_date
datetime.date(1938, 6, 4)
>>> d3.baked_time
datetime.time(5, 30)
>>> d3.consumed_at
datetime.datetime(2007, 4, 20, 16, 19, 59)

# Year boundary tests (ticket #3689)

>>> d = Donut(name='Date Test 2007', baked_date=datetime.datetime(year=2007, month=12, day=31), consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59))
>>> d.save()
>>> d1 = Donut(name='Date Test 2006', baked_date=datetime.datetime(year=2006, month=1, day=1), consumed_at=datetime.datetime(year=2006, month=1, day=1))
>>> d1.save()

>>> Donut.objects.filter(baked_date__year=2007)
[<Donut: Date Test 2007>]

>>> Donut.objects.filter(baked_date__year=2006)
[<Donut: Date Test 2006>]

>>> Donut.objects.filter(consumed_at__year=2007).order_by('name')
[<Donut: Apple Fritter>, <Donut: Date Test 2007>]

>>> Donut.objects.filter(consumed_at__year=2006)
[<Donut: Date Test 2006>]

>>> Donut.objects.filter(consumed_at__year=2005)
[]

>>> Donut.objects.filter(consumed_at__year=2008)
[]

 N/A N/A N/A settings DATABASE_ENGINE mysql N/A N/A N/A __test__ N/A API_TESTS 
>>> from django.utils import tzinfo 
>>> dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0)) 
>>> d = Donut(name='Bear claw', consumed_at=dt) 
>>> d.save()
Traceback (most recent call last):
    ....
ValueError: MySQL backend does not support timezone-aware datetimes.
