So I have a model that has a dateField and a dateTimeField. What I want is de Django database to exclude the date field from the dateTimeField.
My models.py
class WordTable(models.Model): session_ID = models.IntegerField() user_ID = models.IntegerField() date = models.DateField() hour = models.DateTimeField() run_label = models.BooleanField() status = models.BooleanField()
As you can see I have a date and an hour field. What I want is the hour field only to show the hour. How can I format that field to do what I want? help is much appreciated.
Advertisement
Answer
To only store Time you can use TimeField
docs instead of using DateTimeField
which does not store a date with it.
TimeField
class TimeField(auto_now=False, auto_now_add=False, **options)
A time, represented in Python by adatetime.time
instance. Accepts the same auto-population options as DateField. The default form widget for this field is a TimeInput. The admin adds some JavaScript shortcuts.