Reputation: 3569
In my models.py I have a GTTime model:
class GTTime(models.Model):
gt_time = models.DateTimeField(null=True)
ctime = models.DateTimeField(auto_now_add=True)
uptime = models.DateTimeField(auto_now=True)
And in my views.py, how to add the time to in the gt_time?
I tried use the time.time()
to pass the timestamp, but there will report error:
gt = models.GTTime(gt_time=time.time())
gt.save()
Error: TypeError: expected string or buffer
Upvotes: 0
Views: 388
Reputation: 26886
From the django datetime doc
A date and time, represented in Python by a datetime.datetime instance. Takes the same extra arguments as DateField.
but you you gives a time instance, take the bellow code:
gt = models.GTTime(testTime=datetime.now())
gt.save()
Upvotes: 3