diff options
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/database-functions.txt | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 28d489d256..acca4a7c68 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -358,8 +358,7 @@ as ``__(lookup_name)``, e.g. ``__year``. Since ``DateField``\s don't have a time component, only ``Extract`` subclasses that deal with date-parts can be used with ``DateField``:: - >>> from datetime import datetime - >>> from django.utils import timezone + >>> from datetime import datetime, timezone >>> from django.db.models.functions import ( ... ExtractDay, ExtractMonth, ExtractQuarter, ExtractWeek, ... ExtractIsoWeekDay, ExtractWeekDay, ExtractIsoYear, ExtractYear, @@ -409,8 +408,7 @@ Each class is also a ``Transform`` registered on ``DateTimeField`` as ``DateTimeField`` examples:: - >>> from datetime import datetime - >>> from django.utils import timezone + >>> from datetime import datetime, timezone >>> from django.db.models.functions import ( ... ExtractDay, ExtractHour, ExtractMinute, ExtractMonth, ... ExtractQuarter, ExtractSecond, ExtractWeek, ExtractIsoWeekDay, @@ -447,6 +445,7 @@ to that timezone before the value is extracted. The example below converts to the Melbourne timezone (UTC +10:00), which changes the day, weekday, and hour values that are returned:: + >>> from django.utils import timezone >>> import zoneinfo >>> melb = zoneinfo.ZoneInfo('Australia/Melbourne') # UTC+10:00 >>> with timezone.override(melb): @@ -620,10 +619,9 @@ with less precision. ``expression`` can have an ``output_field`` of either Since ``DateField``\s don't have a time component, only ``Trunc`` subclasses that deal with date-parts can be used with ``DateField``:: - >>> from datetime import datetime + >>> from datetime import datetime, timezone >>> from django.db.models import Count >>> from django.db.models.functions import TruncMonth, TruncYear - >>> from django.utils import timezone >>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=timezone.utc) >>> start2 = datetime(2015, 6, 15, 14, 40, 2, 123, tzinfo=timezone.utc) >>> start3 = datetime(2015, 12, 31, 17, 5, 27, 999, tzinfo=timezone.utc) @@ -699,12 +697,11 @@ datetimes with less precision. ``expression`` must have an ``output_field`` of Usage example:: - >>> from datetime import date, datetime + >>> from datetime import date, datetime, timezone >>> from django.db.models import Count >>> from django.db.models.functions import ( ... TruncDate, TruncDay, TruncHour, TruncMinute, TruncSecond, ... ) - >>> from django.utils import timezone >>> import zoneinfo >>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=timezone.utc) >>> Experiment.objects.create(start_datetime=start1, start_date=start1.date()) @@ -753,10 +750,9 @@ with less precision. ``expression`` can have an ``output_field`` of either Since ``TimeField``\s don't have a date component, only ``Trunc`` subclasses that deal with time-parts can be used with ``TimeField``:: - >>> from datetime import datetime + >>> from datetime import datetime, timezone >>> from django.db.models import Count, TimeField >>> from django.db.models.functions import TruncHour - >>> from django.utils import timezone >>> start1 = datetime(2014, 6, 15, 14, 30, 50, 321, tzinfo=timezone.utc) >>> start2 = datetime(2014, 6, 15, 14, 40, 2, 123, tzinfo=timezone.utc) >>> start3 = datetime(2015, 12, 31, 17, 5, 27, 999, tzinfo=timezone.utc) |
