尝试在模型表单中添加新HTML属性时出现Django错误

尝试在模型表单中添加新HTML属性时出现Django错误,django,django-forms,Django,Django Forms,我有这个型号 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 =

我有这个型号

 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行时,一切正常。我认为Django错误消息与我的实际错误无关。离题:我发现forms.py文件中的错误往往会引发错误消息,有时会让您走上错误的道路。

也许您需要从模型中创建表单并对其进行自定义,这是官方文档

用于使用HTML属性进行自定义。我是从django.forms导入表单,而不是从django导入表单

Exception Value: Caught ViewDoesNotExist while rendering: Could not import registration.views.item_details. View does not exist in module registration.views.