我有這個模型Django的錯誤模型的形式屬性
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文件中的錯誤往往會引發錯誤消息,有時會讓你誤入歧途。