Opened 3 years ago

Closed 3 years ago

#32359 closed New feature (wontfix)

Should we define __round__ on Expression?

Reported by: Willem Van Onsem Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: aggregates
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Rounding values can be done with:

from django.db.models.functions import Round


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:


A potential problem with this is that people might expect that this will itself return a number-like object, and not an expression.

Change History (1)

comment:1 by Simon Charette, 3 years ago

Resolution: wontfix
Status: newclosed

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).

Note: See TracTickets for help on using tickets.
Back to Top