MCPcopy
hub / github.com/django/django / datetimes

Method datetimes

django/db/models/query.py:1597–1628  ·  view source on GitHub ↗

Return a list of datetime objects representing all available datetimes for the given field_name, scoped to 'kind'.

(self, field_name, kind, order="ASC", tzinfo=None)

Source from the content-addressed store, hash-verified

1595 )
1596
1597 def datetimes(self, field_name, kind, order="ASC", tzinfo=None):
1598 """
1599 Return a list of datetime objects representing all available
1600 datetimes for the given field_name, scoped to 'kind'.
1601 """
1602 if kind not in ("year", "month", "week", "day", "hour", "minute", "second"):
1603 raise ValueError(
1604 "'kind' must be one of 'year', 'month', 'week', 'day', "
1605 "'hour', 'minute', or 'second'."
1606 )
1607 if order not in ("ASC", "DESC"):
1608 raise ValueError("'order' must be either 'ASC' or 'DESC'.")
1609 if settings.USE_TZ:
1610 if tzinfo is None:
1611 tzinfo = timezone.get_current_timezone()
1612 else:
1613 tzinfo = None
1614 return (
1615 self.annotate(
1616 datetimefield=Trunc(
1617 field_name,
1618 kind,
1619 output_field=DateTimeField(),
1620 tzinfo=tzinfo,
1621 ),
1622 plain_field=F(field_name),
1623 )
1624 .values_list("datetimefield", flat=True)
1625 .distinct()
1626 .filter(plain_field__isnull=False)
1627 .order_by(("-" if order == "DESC" else "") + "datetimefield")
1628 )
1629
1630 def none(self):
1631 """Return an empty QuerySet."""

Callers 15

get_date_listMethod · 0.80
test_ticket7155Method · 0.80
test_ticket7791Method · 0.80
test_unicode_dateMethod · 0.80
test_query_datetimesMethod · 0.80
test_query_datetimesMethod · 0.80
test_datetimes_aliasMethod · 0.80
test_issue_7105Method · 0.80

Calls 8

annotateMethod · 0.95
TruncClass · 0.90
DateTimeFieldClass · 0.90
FClass · 0.90
order_byMethod · 0.80
distinctMethod · 0.80
values_listMethod · 0.80
filterMethod · 0.45

Tested by 15

test_ticket7155Method · 0.64
test_ticket7791Method · 0.64
test_unicode_dateMethod · 0.64
test_query_datetimesMethod · 0.64
test_query_datetimesMethod · 0.64
test_datetimes_aliasMethod · 0.64
test_issue_7105Method · 0.64
test_dates_queryMethod · 0.64