{{{
from django.db.models.functions import Round
Round(Count('related_model'))
}}}
But we could also implement the __round__ function on the Expression
class, and thus use Python's round(...) function, then it thus no longer
requires an import:
{{{
round(Count('related_model'))
}}}
A potential problem with this is that people might expect that this will
itself return a number-like object, and not an expression.
--
Ticket URL: <https://code.djangoproject.com/ticket/32359>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => wontfix
Comment:
Thanks for the suggestion but I think that sticking to the explicit import
makes for a more cohesive expression interface.
I don't think that avoiding an import is a good enough justification to
support two ways of achieving a similar result even if we were to adopt
this pattern for other ''magic'' functions (e.g. `__abs__` ->
`django.db.models.functions.Abs`).
--
Ticket URL: <https://code.djangoproject.com/ticket/32359#comment:1>