Reputation: 31
In django form, I would like an input for a time with a format only with hour and minutes. But I keep having second on my web page. Anyone could help Thank you
models.py
Class Recettes(models.Model) :
…
temps_preparation = models.TimeField(
db_column='Temps_Preparation',
help_text = 'veuillez saisir le temps sous la forme heure:minute(HH:MM)',
blank=True,
null=True,
)
….
settings.py
...
TIME_INPUT_FORMATS = [ '%I:%M']
forms.py
class RecetteForm(forms.ModelForm) :
temps_préparation = TimeField(input_formats = ['%H:%M',], label='Temps de préparation – HH:MM')
Upvotes: 3
Views: 12814
Reputation: 181
You need to add a single line to the settings.py
file and it will change the time formatting across all the apps in your project.
add this to the settings.py
file:
TIME_INPUT_FORMATS = ('%I:%M %p',)
TIME_INPUT_FORMATS = ('%H:%M',)
Upvotes: 5
Reputation: 182
in setting.py add
'DATETIME_FORMAT': "%m-%d - %M:%S"
in models.py
temps_preparation = models.DateTimeField(null=True)
and in form.py
datetime.strptime(yourdate, "%M:%S")
Upvotes: 1