Skip to content
Snippets Groups Projects
format.py 418 B
Newer Older
Jonathan Weth's avatar
Jonathan Weth committed
from datetime import date

from django.utils.formats import date_format


Jonathan Weth's avatar
Jonathan Weth committed
def format_m2m(f, attr: str = "short_name") -> str:
    """Join a attribute of all elements of a ManyToManyField."""
    return ", ".join([getattr(x, attr) for x in f.all()])


Jonathan Weth's avatar
Jonathan Weth committed
def format_date_period(day: date, period: "TimePeriod") -> str:
Jonathan Weth's avatar
Jonathan Weth committed
    """Format date and time period."""
    return f"{date_format(date_format(day))}, {period.period}."