Skip to content

Default funcs

django_rubble.utils.default_funcs

Useful functions for default values in Django models.

django_now()

Return the current datetime in the timezone of the Django settings.

Example:

from django_rubble.utils.default_funcs import django_now django_now() datetime.datetime(2021, 1, 1, 0, 0, tzinfo=)

Source code in django_rubble\utils\default_funcs.py
19
20
21
22
23
24
25
26
27
def django_now() -> datetime:
    """Return the current datetime in the timezone of the Django settings.

    Example:
    >>> from django_rubble.utils.default_funcs import django_now
    >>> django_now()
    datetime.datetime(2021, 1, 1, 0, 0, tzinfo=<UTC>)
    """
    return timezone.now()

django_today()

Return the current date in the timezone of the Django settings.

Example

from django_rubble.utils.default_funcs import django_today django_today() datetime.date(2021, 1, 1)

Source code in django_rubble\utils\default_funcs.py
 8
 9
10
11
12
13
14
15
16
def django_today() -> date:
    """Return the current date in the timezone of the Django settings.

    Example:
        >>> from django_rubble.utils.default_funcs import django_today
        >>> django_today()
        datetime.date(2021, 1, 1)
    """
    return timezone.now().date()