MCPcopy
hub / github.com/django/django / dates

Method dates

django/db/models/query.py:1577–1595  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

1575 return clone
1576
1577 def dates(self, field_name, kind, order="ASC"):
1578 """
1579 Return a list of date objects representing all available dates for
1580 the given field_name, scoped to 'kind'.
1581 """
1582 if kind not in ("year", "month", "week", "day"):
1583 raise ValueError("'kind' must be one of 'year', 'month', 'week', or 'day'.")
1584 if order not in ("ASC", "DESC"):
1585 raise ValueError("'order' must be either 'ASC' or 'DESC'.")
1586 return (
1587 self.annotate(
1588 datefield=Trunc(field_name, kind, output_field=DateField()),
1589 plain_field=F(field_name),
1590 )
1591 .values_list("datefield", flat=True)
1592 .distinct()
1593 .filter(plain_field__isnull=False)
1594 .order_by(("-" if order == "DESC" else "") + "datefield")
1595 )
1596
1597 def datetimes(self, field_name, kind, order="ASC", tzinfo=None):
1598 """

Calls 8

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