Javascript Django:日期格式管理和唯一性结合起来->&引用;2020年3月20日“;值的日期格式无效。它必须是YYYY-MM-DD格式。”;]
我用国际化英语/法语开发了一个Django项目 当用户webbrowser为FR时,日期必须以dd/mm/yyyy格式显示;当用户webbrowser为EN时,日期必须以yyyy-mm-dd格式显示 为此,我使用JS测试webbrowser用户最喜欢的语言和相应的显示格式 这很好,直到我将模型更改为将unique_与此日期一起添加约束 现在,当webbrowser使用法语时,我遇到了一个错误,我尝试注册日期(asp\u entu dat) 型号。py:Javascript Django:日期格式管理和唯一性结合起来->&引用;2020年3月20日“;值的日期格式无效。它必须是YYYY-MM-DD格式。”;],javascript,python,django,date,Javascript,Python,Django,Date,我用国际化英语/法语开发了一个Django项目 当用户webbrowser为FR时,日期必须以dd/mm/yyyy格式显示;当用户webbrowser为EN时,日期必须以yyyy-mm-dd格式显示 为此,我使用JS测试webbrowser用户最喜欢的语言和相应的显示格式 这很好,直到我将模型更改为将unique_与此日期一起添加约束 现在,当webbrowser使用法语时,我遇到了一个错误,我尝试注册日期(asp\u entu dat) 型号。py: class Entree(models.M
class Entree(models.Model):
asp_ent_cle = models.AutoField(primary_key=True)
asp_ent_loc = models.CharField("Site concerned by the operation", max_length=10, null=True, blank=True)
med_num = models.CharField("Trial batch number", max_length=3, null=True, blank=True,)
asp_ent_dat = models.DateField("Entry date", null=True, blank=True)
asp_ent_pro_pay = models.CharField("Country of treatment origin in case of entry", max_length=10, null=True, blank=True)
asp_ent_pro_sit = models.CharField("Processing source site in case of entry", max_length=10, null=True, blank=True)
opr_nom = models.CharField("Input operator", max_length=10, null=True, blank=True)
opr_dat = models.DateField("Entry date", null=True, blank=True)
log = HistoricalRecords()
class Meta:
db_table = 'pha_asp_ent'
verbose_name_plural = 'Entries'
ordering = ['asp_ent_cle']
unique_together = ['asp_ent_loc','med_num','asp_ent_dat']
$(function(){
if(window.navigator.language == 'fr-FR' | window.navigator.language == 'fr'){
$("#id_asp_ent_dat").datepicker(
{
dateFormat: 'dd/mm/yy',
}
);
}
else
{
$("#id_asp_ent_dat").datepicker(
{
dateFormat: 'yy-mm-dd',
}
);
});
def clean(self):
cleaned_data = super(EditForm, self).clean()
cle1 = self.data.get('asp_ent_loc')
cle2 = self.data.get('med_num')
# cle3 = self.data.get('asp_ent_dat') ***LINE THAT RAISE ERROR***
cle3 = self.cleaned_data['asp_ent_dat']
JS:
class Entree(models.Model):
asp_ent_cle = models.AutoField(primary_key=True)
asp_ent_loc = models.CharField("Site concerned by the operation", max_length=10, null=True, blank=True)
med_num = models.CharField("Trial batch number", max_length=3, null=True, blank=True,)
asp_ent_dat = models.DateField("Entry date", null=True, blank=True)
asp_ent_pro_pay = models.CharField("Country of treatment origin in case of entry", max_length=10, null=True, blank=True)
asp_ent_pro_sit = models.CharField("Processing source site in case of entry", max_length=10, null=True, blank=True)
opr_nom = models.CharField("Input operator", max_length=10, null=True, blank=True)
opr_dat = models.DateField("Entry date", null=True, blank=True)
log = HistoricalRecords()
class Meta:
db_table = 'pha_asp_ent'
verbose_name_plural = 'Entries'
ordering = ['asp_ent_cle']
unique_together = ['asp_ent_loc','med_num','asp_ent_dat']
$(function(){
if(window.navigator.language == 'fr-FR' | window.navigator.language == 'fr'){
$("#id_asp_ent_dat").datepicker(
{
dateFormat: 'dd/mm/yy',
}
);
}
else
{
$("#id_asp_ent_dat").datepicker(
{
dateFormat: 'yy-mm-dd',
}
);
});
def clean(self):
cleaned_data = super(EditForm, self).clean()
cle1 = self.data.get('asp_ent_loc')
cle2 = self.data.get('med_num')
# cle3 = self.data.get('asp_ent_dat') ***LINE THAT RAISE ERROR***
cle3 = self.cleaned_data['asp_ent_dat']
forms.py:
class Entree(models.Model):
asp_ent_cle = models.AutoField(primary_key=True)
asp_ent_loc = models.CharField("Site concerned by the operation", max_length=10, null=True, blank=True)
med_num = models.CharField("Trial batch number", max_length=3, null=True, blank=True,)
asp_ent_dat = models.DateField("Entry date", null=True, blank=True)
asp_ent_pro_pay = models.CharField("Country of treatment origin in case of entry", max_length=10, null=True, blank=True)
asp_ent_pro_sit = models.CharField("Processing source site in case of entry", max_length=10, null=True, blank=True)
opr_nom = models.CharField("Input operator", max_length=10, null=True, blank=True)
opr_dat = models.DateField("Entry date", null=True, blank=True)
log = HistoricalRecords()
class Meta:
db_table = 'pha_asp_ent'
verbose_name_plural = 'Entries'
ordering = ['asp_ent_cle']
unique_together = ['asp_ent_loc','med_num','asp_ent_dat']
$(function(){
if(window.navigator.language == 'fr-FR' | window.navigator.language == 'fr'){
$("#id_asp_ent_dat").datepicker(
{
dateFormat: 'dd/mm/yy',
}
);
}
else
{
$("#id_asp_ent_dat").datepicker(
{
dateFormat: 'yy-mm-dd',
}
);
});
def clean(self):
cleaned_data = super(EditForm, self).clean()
cle1 = self.data.get('asp_ent_loc')
cle2 = self.data.get('med_num')
# cle3 = self.data.get('asp_ent_dat') ***LINE THAT RAISE ERROR***
cle3 = self.cleaned_data['asp_ent_dat']
将有效的日期格式添加到
日期\u输入\u格式
将有效的日期格式添加到
日期输入格式中
感谢您的回复,我添加了日期输入格式['%Y-%m-%d','%d/%m/%Y',],但仍然存在错误2020年3月20日('%d/%m/%Y')似乎不是文档中授权的格式列表,我将测试它。这对我有用。您使用的是什么
datepicker
?JQuery datepickerDid您已将其添加到设置中。py
?感谢您的回复我添加了日期输入格式['%Y-%m-%d','%d/%m/%Y',],但仍然存在错误2020年3月20日('%d/%m/%Y')似乎不是文档中授权的格式列表我测试它。这对我有用。您使用的是什么datepicker
?JQuery datepickerDid是否已将其添加到设置.py
?