django - django DateField 是字符域
问题描述
我正在使用 django.forms ModelForm。我有 DoB,它是“日期字段”,但是,当我显示 DoB 的表单时,它像 charfield 一样显示。我应该怎么做才能让用户能够选择日期?任何帮助表示赞赏。谢谢
模型:
dob = models.DateField(validators=[MinValueValidator(18), MaxValueValidator(70)],blank=True, null = True, verbose_name="Day of birth")
HTML:
<form method = 'POST' >
{{ edit_profile | crispy}}
{% csrf_token %}
<button type = 'submit' name = 'submit' class = 'btn-edit'>Save</button>
</form>
解决方案
I have faced an issue like this in the past. There is a very small fix for this. In your forms.py
make the following changes:
from django.forms import ModelForm
from .models import Model_Name
class EquipmentForm(ModelForm):
class Meta:
model = Model_Name
fields = 'dob'
widgets = {'dob': DateInput()}
This should solve your issue
推荐阅读
- android - 什么是 Expo React-native 中的 DangerZone
- python - 如何每 3 个选择的元素中的 10 个元素对 numpy 数组进行二次采样
- javascript - 导航到另一条路线时重新加载数据而不刷新组件
- image-processing - 两幅图像的RGB直方图之间的欧几里得距离
- django - 部署到 Heroku 后如何删除“OperationalError at / no such table: subreddit_subreddit”?
- angular - Material Mat-Stepper Horizontal - 如何将标题放置在内容下方?
- angular - Angular & Spring Boot 2 & OAuth2 客户端
- automated-tests - 赛普拉斯 - 如果函数超时
- python - 将列组与布尔值组合以创建多个新列
- javascript - 如何在 chart.js 中添加额外的图例项?