Return a list of date objects representing all available dates for the given field_name, scoped to 'kind'.
(self, field_name, kind, order="ASC")
| 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 | """ |