我在编辑表单时遇到日期问题。
model.py
class Promotions(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=10000)
status = models.CharField(max_length=100)
website = models.CharField(max_length=100)
start_date = models.DateTimeField()
expire_date = models.DateTimeField()
forms.py
class PromotionsForm(forms.ModelForm):
CHOICES = (('Active','Active'),('Inactive', 'Inactive'))
WEBSITE = (("CMS","CMS"),("Tutor","Tutor"),("Offers","Offers"),
("Promotions","Promotions"),("Orders","Orders"))
status = forms.ChoiceField(choices=CHOICES)
website = forms.MultipleChoiceField(choices=WEBSITE, widget=forms.SelectMultiple)
start_date = forms.DateField(widget=forms.TextInput(attrs={'class':'datepicker'}))
expire_date = forms.DateField(widget=forms.TextInput(attrs={'class':'datepicker'}))
class Meta:
model = Promotions
fields = ["name", "description", "status", "website", "start_date", "expire_date"]
当我提供输入时
我在编辑时模板
请帮忙 谢谢。
答案 0 :(得分:1)
模型中的字段类型expire_date
和start_date
与表单中的字段类型不匹配。
值将存储为DateTime而不是Date。
在您的模型中,将start_date
和expiry_date
更改为DateField
class Promotions(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=10000)
status = models.CharField(max_length=100)
website = models.CharField(max_length=100)
start_date = models.DateField()
expire_date = models.DateField()