【发布时间】:2021-06-06 17:49:42
【问题描述】:
我需要在我的查询集中为 Value1 使用 if else 条件..我在查询集中找到了我的记录的平均值..我需要应用类似的条件..如果我的 Value1 在 90 到 110 之间,那么我必须得到消息为“大”,如果低于 90,则必须打印为“低”,如果高于 140,则必须打印为“高”
我需要在我的 html 文件上打印这个输出
模型.py:
from django.db import models
from django.contrib.auth.models import User
class graphinput(models.Model):
user=models.ForeignKey(User,on_delete=models.CASCADE)
Month = models.CharField(max_length=30)
Value1 = models.IntegerField()
Value2 = models.IntegerField()
urls.py:
def average(request):
userid = None
if request.user.is_authenticated:
userid = request.user.id
print(userid)
dataset = graphinput.objects.filter(user=userid) \
.values('Value1')
a=dataset.aggregate(Sum('Value1'))
b=dataset.aggregate(Avg('Value1'))
print(a)
print(b)
return render(request, 'profile.html')
【问题讨论】:
标签: python django django-models