我有一个简单的模型:
from scipy import stats as st
import numpy as np
import random
total=30
totalA=12
totalB=18
def transistor():
return random.choice("A","B")
random.seed(0)
for _in range(30):
try1=transistor()
try2=transistor()
if try1="A":
prob1=totalA/total
else:
prob1=totalB/total
if try2="A":
prob2=totalA/total
else:
prob2=totalB/total
if try1=="A" and try2=="A"
prob=2*totalA/total
进度字段存储百分比值:
例如52%将存储为0.52
我的表单如下:
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
progress = models.DecimalField(max_digits=5, decimal_places=4)
我的问题是,如何将这个值转换回UpdateView中? 表单中预填了数据库中的值。数据库中的值为0.52,但我希望表单中预先填充52。
答案 0 :(得分:1)
首先添加到您的UpdateView hours
属性:
minutes
然后在form_class
中覆盖class PersonUpdateView(UpdateView):
....
form_class = PersonForm
....
方法:
PersonForm