gpt4 book ai didi

django - 从 Django 十进制 ModelForm 字段中删除向上和向下箭头

转载 作者:行者123 更新时间:2023-12-02 05:56:18 25 4
gpt4 key购买 nike

我的十进制 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" >&nbsp;Save & Close</button>
</div>
</form>

最佳答案

您可以覆盖 ModelForm 字段以使用您喜欢的任何小部件,如下所示:

class AuthorForm(ModelForm):

class Meta:
model = Author
fields = ('name', 'title', 'birth_date')
widgets = {
'name': TextInput(attrs={'placeholder': 'That dude cray'}),
}

关于django - 从 Django 十进制 ModelForm 字段中删除向上和向下箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21342789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com