Bonjour,
je travaille depuis peu avec Django et je galère un peu sur les dates (format datetime) j’ai mis en place un formulaire avec un champ datetime sur lequel je souhaite
- afficher un datepicker et
- une valeur par défaut à now()
j’ai essayé de le faire via un widget/attrs (mais je n’ai pas le format datepicker que je cherche type calendrier boostrap) et initial mais je n’ai pas le format date heure j’ai essayé via JQuery (en ajoutant une classe 'datepicker' sur laquelle j’ajoute .datepicker() mais çà ne fonctionne pas
comment puis-je implémenter ?
forms.py
from django import forms
from .models import Randomisation
import datetime
import time
class RandomisationForm(forms.ModelForm):
TYPES = [
(1, 'On-line'),
(2, 'Telephon'),
]
YESNO = [
(1, 'Yes'),
(0, 'No'),
]
TB = [
(1, 'Possible'),
(2, 'Probable'),
(3, 'Definite'),
]
SEVERITY = [
(1, 'Mild'),
(2, 'Severe'),
]
HIV = [
(0, 'Negative'),
(1, 'Positive'),
]
ran_num = forms.CharField(label="Patient code", widget=forms.HiddenInput())
# ran_bra = forms.IntegerField(label="TB treatment assigned", widget=forms.HiddenInput())
# ran_med = forms.IntegerField(label="Batch number", widget=forms.HiddenInput())
# ran_num = forms.CharField(label="Patient code", widget=forms.TextInput(attrs={'readonly':'readonly'}))
ran_dat = forms.DateField(
label = "Today's date",
initial = datetime.datetime.now,
# widget = forms.DateInput(
# attrs = {
# 'type': 'date',
# 'placeholder' : 'Date',
# 'class':'datepicker',
# }
# )
)
ran_pro = forms.ChoiceField(label="Type", widget=forms.Select, choices=TYPES)
ran_crf_inc = forms.ChoiceField(label="Was the CRF inclusion 2 Eligibility fulfilled?", widget=forms.Select, choices=YESNO)
ran_crf_eli = forms.ChoiceField(label="Was the CRF Inclusion 2 Eligibility fulffiled?", widget=forms.Select, choices=YESNO)
ran_tbc = forms.ChoiceField(label="Is TB diagnosis possible, probable or definite?", widget=forms.Select, choices=TB)
ran_cri = forms.ChoiceField(label="Is the conclusion All criteria fulfilled for randomisation", widget=forms.Select, choices=YESNO)
ran_sta = forms.ChoiceField(label="British Medical Council Staging (worst stage reported between first symptoms and now)", widget=forms.Select, choices=SEVERITY)
ran_vih = forms.ChoiceField(label="HIV/AIDS status", widget=forms.Select, choices=HIV)
class Meta:
model = Randomisation
# Tous les champs sauf les champs de log et les champs TB treatment et Drug batch number
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',)
models.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.DateTimeField("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.CharField("Batch number", max_length=6, null=True, blank=True)
ran_log_dat = models.DateTimeField("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}"
+0
-0