Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python DatePicker使用ModelForm不可见-crispy_Python_Django - Fatal编程技术网

Python DatePicker使用ModelForm不可见-crispy

Python DatePicker使用ModelForm不可见-crispy,python,django,Python,Django,我有一个基于模型随机化的模型 我在模板(randomization_edit.html)中使用crispy,在表单(randomization表单)中使用DateInput() 不幸的是,我的编辑表单中没有DatePicker 有什么问题 forms.py 来自django导入表单的 模型导入随机化 类RandomisationForm(forms.ModelForm): 类型=[ (1,“在线”), (2,“电话”), ] ran_num=forms.CharField(label=“Pati

我有一个基于模型随机化的模型 我在模板(randomization_edit.html)中使用crispy,在表单(randomization表单)中使用DateInput()

不幸的是,我的编辑表单中没有DatePicker

有什么问题

forms.py

来自django导入表单的

模型导入随机化
类RandomisationForm(forms.ModelForm):
类型=[
(1,“在线”),
(2,“电话”),
]
ran_num=forms.CharField(label=“Patient code”,disabled=True)
ran_dat=forms.DateInput()
ran_pro=forms.ChoiceField(label=“Type”,widget=forms.Select,choices=TYPES)
类元:
模型=随机化
字段=('ran_num'、'ran_dat'、'ran_inv'、'ran_pro'、'ran_pro_per'、'ran_crf_inc'、'ran_tbc'、'ran_crf_eli'、'ran_cri'、'ran_sta'、'ran_vih'、'ran_bra'、'ran_med')
models.py

类随机化(models.Model):
ran\u ide=models.AutoField(主键=True)
ran_num=models.CharField(“患者代码”,最大长度=10,唯一性=True,null=True,blank=True)
ran_dat=models.DateTimeField(“今天的日期”,null=True,blank=True)
ran_inv=models.CharField(“调查者”,最大长度=20,null=True,blank=True)
ran_pro=models.IntegerField(“用于随机化的过程”,null=True,blank=True)
ran_pro_per=models.IntegerField(“如果是电话,则是电话上联系到的人的姓名”,null=True,blank=True)
ran_crf_inc=models.IntegerField(“crf包含2的资格是否满足?”,null=True,blank=True)
ran_tbc=models.IntegerField(“TB诊断是否可能、可能或明确?”,null=True,blank=True)
ran_crf_eli=models.IntegerField(“crf包含2的资格是否已验证?”,null=True,blank=True)
ran_cri=models.IntegerField(“结论是否符合所有随机标准”,null=True,blank=True)
ran_sta=models.IntegerField(“英国医学会分期(从最初症状到现在报告的最差分期)”,null=True,blank=True)
ran_vih=models.IntegerField(“HIV/AIDS状态”,null=True,blank=True)
ran_bra=models.IntegerField(“TB治疗分配”,null=True,blank=True)
ran\u med=models.IntegerField(“批号”,null=True,blank=True)
ran_log_dat=models.datetime字段(“日期”,null=True,blank=True)
ran_log=models.CharField(“现场执行随机化的人员的姓名”,最大长度=10,null=True,blank=True)
类元:
db_表='crf_ran'
详细名称\u复数='随机化'
排序=['ran_num']
定义(自我):
返回f“{self.ran_ide}”
随机化_edit.html

{%extends'布局/base.html%}
{%load static%}
{%load crispy_forms_tags%}
{%block title%}索引{%endblock%}
{%block content%}
随机化形式

{%csrf_令牌%} {{form | crispy}} 随机化



{%endblock%}
DateTimefield的问题在于该字段的默认输入类型是
TextInput
,因此html无法将其识别为
type=date
,因为表单中没有显示日期选择器。 要将输入类型更改为
datetime local
date
,您必须使用django中的小部件来帮助处理特定的html输入代码。 特别针对这种情况,您可以尝试以下方法,看看是否有效:

型号.py

class Randomisation(models.Model):

ran_ide = models.AutoField(primary_key=True)
ran_num = models.CharField("Patient code", max_length=10, unique=True, null=True, blank=True)
ran_dat = models.DateField("Today's date", null=True, blank=True)
ran_inv = models.CharField("Investigator", max_length=20, null=True, blank=True)
ran_pro = models.IntegerField("Procedure used to randomized", null=True, blank=True)
ran_pro_per = models.IntegerField("if telephone, name of the person reached on the phone", null=True, blank=True)
ran_crf_inc = models.IntegerField("Was the CRF inclusion 2 Eligibility fulfilled?", null=True, blank=True)
ran_tbc = models.IntegerField("Is TB diagnosis possible, probable or definite?", null=True, blank=True)
ran_crf_eli = models.IntegerField("Was the CRF Inclusion 2 Eligibility fulffiled?", null=True, blank=True)
ran_cri = models.IntegerField("Is the conclusion All criteria fulfilled for randomisation", null=True, blank=True)
ran_sta = models.IntegerField("British Medical Council Staging (worst stage reported between first symptoms and now)", null=True, blank=True)
ran_vih = models.IntegerField("HIV/AIDS status", null=True, blank=True)
ran_bra = models.IntegerField("TB treatment assigned", null=True, blank=True)
ran_med = models.IntegerField("Batch number", null=True, blank=True)
ran_log_dat = models.DateField("Date", null=True, blank=True)
ran_log = models.CharField("Name of the person who performs randomisation on site", max_length=10, null=True, blank=True)

class Meta:

    db_table = 'crf_ran'
    verbose_name_plural = 'randomized'
    ordering = ['ran_num']

def __str__(self):

    return f"{self.ran_ide}"
from django import forms
from .models import Randomisation

class RandomisationForm(forms.ModelForm):

TYPES = [
    (1, 'On-line'),
    (2, 'Telephon'),
]
ran_num = forms.CharField(label="Patient code",disabled=True)
ran_dat = forms.DateField(
          widget=forms.TextInput(
        attrs={
            'type': 'date',
            'placeholder' : 'Date',
        }
    )
)
ran_pro = forms.ChoiceField(label="Type", widget=forms.Select, choices=TYPES)

class Meta:
    model = Randomisation
    fields = ('ran_num','ran_dat','ran_inv','ran_pro','ran_pro_per','ran_crf_inc','ran_tbc','ran_crf_eli','ran_cri','ran_sta','ran_vih','ran_bra','ran_med',)
forms.py

class Randomisation(models.Model):

ran_ide = models.AutoField(primary_key=True)
ran_num = models.CharField("Patient code", max_length=10, unique=True, null=True, blank=True)
ran_dat = models.DateField("Today's date", null=True, blank=True)
ran_inv = models.CharField("Investigator", max_length=20, null=True, blank=True)
ran_pro = models.IntegerField("Procedure used to randomized", null=True, blank=True)
ran_pro_per = models.IntegerField("if telephone, name of the person reached on the phone", null=True, blank=True)
ran_crf_inc = models.IntegerField("Was the CRF inclusion 2 Eligibility fulfilled?", null=True, blank=True)
ran_tbc = models.IntegerField("Is TB diagnosis possible, probable or definite?", null=True, blank=True)
ran_crf_eli = models.IntegerField("Was the CRF Inclusion 2 Eligibility fulffiled?", null=True, blank=True)
ran_cri = models.IntegerField("Is the conclusion All criteria fulfilled for randomisation", null=True, blank=True)
ran_sta = models.IntegerField("British Medical Council Staging (worst stage reported between first symptoms and now)", null=True, blank=True)
ran_vih = models.IntegerField("HIV/AIDS status", null=True, blank=True)
ran_bra = models.IntegerField("TB treatment assigned", null=True, blank=True)
ran_med = models.IntegerField("Batch number", null=True, blank=True)
ran_log_dat = models.DateField("Date", null=True, blank=True)
ran_log = models.CharField("Name of the person who performs randomisation on site", max_length=10, null=True, blank=True)

class Meta:

    db_table = 'crf_ran'
    verbose_name_plural = 'randomized'
    ordering = ['ran_num']

def __str__(self):

    return f"{self.ran_ide}"
from django import forms
from .models import Randomisation

class RandomisationForm(forms.ModelForm):

TYPES = [
    (1, 'On-line'),
    (2, 'Telephon'),
]
ran_num = forms.CharField(label="Patient code",disabled=True)
ran_dat = forms.DateField(
          widget=forms.TextInput(
        attrs={
            'type': 'date',
            'placeholder' : 'Date',
        }
    )
)
ran_pro = forms.ChoiceField(label="Type", widget=forms.Select, choices=TYPES)

class Meta:
    model = Randomisation
    fields = ('ran_num','ran_dat','ran_inv','ran_pro','ran_pro_per','ran_crf_inc','ran_tbc','ran_crf_eli','ran_cri','ran_sta','ran_vih','ran_bra','ran_med',)
我建议你也去看看。 我希望这有帮助。
请随时提出进一步的疑问。

谢谢您的回复!它起作用了!我将寻找另一个小部件,提出了一个日期选择器,如引导好!!如果答案有效,请随意接受!!