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
JavaScript
x
8
1
class WordTable(models.Model):
2
session_ID = models.IntegerField()
3
user_ID = models.IntegerField()
4
date = models.DateField()
5
hour = models.DateTimeField()
6
run_label = models.BooleanField()
7
status = models.BooleanField()
8
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.