我有一张名为RoundTable
的表,它有2个字段,最多座位数和当前占用的座位数。我想找到这两列之间的最大差异。
我的模特:
class RoundTable(models.Model):
total_seats = models.SmallIntegerField(validators=[MinValueValidator(1)])
occupied_seats = models.SmallIntegerField(validators=[MinValueValidator(1)])
.... other fields
查询会是什么样的?
RoundTable.objects.aggregate(?)
答案 0 :(得分:4)
应该是这样的:
<head>
<script>
let car = CarFunction();
function CarFunction(lang) {
var carNo = (prompt("Enter Car No"));
if (carNo === '1') {
return('Sedan');
}else if (carNo == '2') {
return('Truck');
} else {
alert('No record found');
}
}
alert(car)
</script>
</head>
<body>
<script>
alert(car)
</script>
答案 1 :(得分:1)
试试这个,
from django.db.models import Max, F, ExpressionWrapper, IntegerField
RoundTable.objects.annotate(diff=ExpressionWrapper(
F('total_seats') - F('occupied_seats'), output_field=IntegerField()
)).aggregate(max=Max('diff'))