我的十进制ModelForm字段在字段中显示“向上/向下箭头”,增加/减少字段的值。
关于我如何移除/隐藏这些箭头的任何反馈?
形式:
class PriceAssessment1Form(forms.ModelForm):
class Meta:
model = Component
fields = ['size_height','size_width','size_length','weight','base_material_price']
模型
class Component(models.Model):
name = models.CharField(max_length=255)
created_date= models.DateTimeField(default=datetime.now)
user = models.ForeignKey(User)
price_assessment_started = models.BooleanField(default=False)
size_height = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)
size_width = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)
size_length = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)
weight = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)
base_material_price = models.DecimalField(null=True,blank=True, max_digits=9, decimal_places=2)
模板
<form action="{% url 'portal_price_assessment' component_id %}" method="post"> {% csrf_token %}
<div>
<div>size_height {{ form.size_height }}</div>
<div>size_width {{ form.size_width }}</div>
<div>size_length {{ form.size_length }}</div>
<div>weight {{ form.weight }}</div>
<div>base_material_price {{ form.base_material_price }}</div>
</div>
<div style="margin-top:18px;">
<a href="{% url 'portal_home' %}" class="btn btn-link">Cancel</a>
<button class="btn" type="submit" > Save & Close</button>
</div>
</form>
答案 0 :(得分:4)
您可以覆盖ModelForm字段以使用您喜欢的任何小部件:
class AuthorForm(ModelForm):
class Meta:
model = Author
fields = ('name', 'title', 'birth_date')
widgets = {
'name': TextInput(attrs={'placeholder': 'That dude cray'}),
}
答案 1 :(得分:1)
我在这里找到答案:Can I hide the HTML5 number input’s spin box?
“箭头”被称为“旋转者”