2016-07-15 38 views
0

我的模板渲染過程中得到錯誤在我看來錯誤觀點 - 「浮動」對象有沒有屬性「標籤」

「浮動」對象有沒有屬性「標籤」

它已做此線I只是增加了一個浮子轉換

form.fields['quantity_order'] = float(bom.quantity) * float(quantity) 

(I加入浮子因爲我得到不同的問題>「不能通過類型的非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

什麼工作你分配一個浮動的領域。爲什麼? –

+3

問題是,你正在分配一個浮動到應該是一個表單字段對象。 – solarissmoke

+2

您可能想在表單的__init__方法中使用'self.fields ['quantity_order']。initial = ...'來分配值 – raphv

回答

0

我會爲我解答

data_dict = { 'quantity_order': float(bom.quantity) * float(quantity)} 

form = Production_orderForm(data_dict) 
相關問題