我有这个模型
40 class Item(models.Model):
41 event = models.ForeignKey(Event)
42 name = models.CharField('Item Name', max_length=50 )
43 description = models.CharField('Description', max_length=150, blank=True, null=True)
44 quantity = models.IntegerField(blank=True, null=True)
45 start = models.DateTimeField('Availability Start Date', blank=True, null=True)
46 end = models.DateTimeField('Expiry Date', blank=True, null=True)
47 cost_price = models.DecimalField('Cost Price Per Item', decimal_places=2, max_digits=10, blank=True, null=True)
48 selling_price = models.DecimalField('Selling Price Per Item', decimal_places=2, max_digits=10, blank=True, null=True)
49
50 def __unicode__(self):
51 return u"%s" % self.name
这个模型形式
39 class ItemForm(forms.ModelForm):
40 description = forms.CharField(label='Description', max_length=250, widget=forms.Textarea, required=False)
41 image = forms.ImageField(label='Item Picture', max_length=50, required=False)
42 start = forms.DateField(widget=SelectDateWidget, required=False)
43 end = forms.DateField(widget=SelectDateWidget, required=False)
55
56 class Meta:
57 model = Item
58 fields = ('image',
59 'name',
60 'description',
61 'quantity',
62 'start',
63 'end',
64 'cost_price',
65 'selling_price',
66 )
67 widgets = {'cost_price': forms.TextInput(attrs={'onChange':'updateSellingPrice()'})}
我正在尝试将新属性添加到cost_price
字段中,该字段将在下面调用js函数:
8 <script type="text/javascript">
9 function updateSellingPrice() {
10 $('#id_cost_price').change(function () {
11 // get cost price
12 var costPrice = $('id_cost_price').text();
13 // set selling price
14 $('$id_selling_price').val(costPrice);
16 })
17 }
18 </script>
在我的模型表单中包含第67行widgets = {'cost_price': forms.TextInput(attrs={'onChange':'updateSellingPrice()'})}
时出现此错误:
Exception Value: Caught ViewDoesNotExist while rendering: Could not import registration.views.item_details. View does not exist in module registration.views.
当我从模型表单中删除第67行时,一切正常/加载。我认为Django错误消息与我的实际错误无关。偏离主题:我发现forms.py文件中的错误往往会引发错误消息,这些消息有时会让你走错路。