因此,我将PostgreSQL和Django用于以下模型
class Example(model.Model):
num = models.DecimalField(max_digits=20, decimal_places=10)
round_to= models.IntegerField()
我希望达到的目标是:
Example.objects.annotate(rounded = Round(F('num'),F('round_to'))
但是Round
函数似乎只允许我舍入到整数。根据:https://docs.djangoproject.com/en/3.0/ref/models/database-functions/#round
内置的} 来调用
Round
函数只舍入到最接近的整数。如果您使用的是postgres,您可以添加自己的数据库函数,通过子类化^{ROUND()
,并在查询中使用它相关问题 更多 >
编程相关推荐