MCPcopy Index your code
hub / github.com/django/django / datetimes

Method datetimes

django/db/models/query.py:1486–1517  ·  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

1484 )
1485
1486 def datetimes(self, field_name, kind, order="ASC", tzinfo=None):
1487 """
1488 Return a list of datetime objects representing all available
1489 datetimes for the given field_name, scoped to 'kind'.
1490 """
1491 if kind not in ("year", "month", "week", "day", "hour", "minute", "second"):
1492 raise ValueError(
1493 "'kind' must be one of 'year', 'month', 'week', 'day', "
1494 "'hour', 'minute', or 'second'."
1495 )
1496 if order not in ("ASC", "DESC"):
1497 raise ValueError("'order' must be either 'ASC' or 'DESC'.")
1498 if settings.USE_TZ:
1499 if tzinfo is None:
1500 tzinfo = timezone.get_current_timezone()
1501 else:
1502 tzinfo = None
1503 return (
1504 self.annotate(
1505 datetimefield=Trunc(
1506 field_name,
1507 kind,
1508 output_field=DateTimeField(),
1509 tzinfo=tzinfo,
1510 ),
1511 plain_field=F(field_name),
1512 )
1513 .values_list("datetimefield", flat=True)
1514 .distinct()
1515 .filter(plain_field__isnull=False)
1516 .order_by(("-" if order == "DESC" else "") + "datetimefield")
1517 )
1518
1519 def none(self):
1520 """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