我在模板渲染过程中的视图中出现错误
'float'对象没有属性'label'
这与我刚刚添加浮动转换
的这一行有关 form.fields['quantity_order'] = float(bom.quantity) * float(quantity)
(我添加浮动,因为我遇到了不同的问题>“不能将序列乘以'十进制'类型的非int”“
@login_required
def Production_order_new(request, pk_bom, pk_soproduct, uri, quantity):
uri = _get_redirect_url(request, uri)
bom = get_object_or_404(BOM, pk=pk_bom)
soproduct = get_object_or_404(SOproduct, pk=pk_soproduct)
if request.method == "POST":
form = Production_orderForm(request.POST)
if form.is_valid():
Production_order= form.save(commit=False)
#contact.author = request.user
Production_order.creation_time = timezone.now()
Production_order.material = bom.material
#Production_order.quantity_order = bom.quantity * quantity
Production_order.SOproduct = soproduct
POmaterial.save()
messages.add_message(request, messages.SUCCESS, "-SUCCESS Object created sucssefully")
return redirect(uri)
else:
form = Production_orderForm()
form.fields['quantity_order'] = float(bom.quantity) * float(quantity)
#form.fields['Vendor_AM'].queryset = Vendor_AM.objects.filter(company=company)
material = bom.material
return render(request, 'production/productionorder_edit.html', {'form': form, 'material':material })
这是我的基本表格
class Production_orderForm(forms.ModelForm):
class Meta:
model = Production_order
fields = ['quantity_order','production_notes', 'agent', 'is_picked']
这就是我在模型
中定义的数量字段的方式quantity_order = models.DecimalField(max_digits=19, decimal_places=3)
可能是什么问题?
答案 0 :(得分:0)
我会回答对我有用的事情
data_dict = { 'quantity_order': float(bom.quantity) * float(quantity)}
form = Production_orderForm(data_dict)