0

Just cannot figure out why Pr gets naive time. The class Pr is added without South, but News is added with South. Pr has no seconds?

class Pr(models.Model):
    time = models.DateTimeField(default=datetime.now)

class News (models.Model):
    timestamp = models.DateTimeField(default=datetime.now) 


>>> a= News.objects.order_by('-id')[0]
>>> a.timestamp
datetime.datetime(2014, 3, 12, 3, 57, 13, tzinfo=<UTC>)

>>> b = Pr.objects.order_by('-id')[0]
>>> b.time
datetime.datetime(2014, 3, 11, 21, 45)
user2443279
  • 41
  • 1
  • 4
  • See http://stackoverflow.com/questions/2771676/django-default-datetime-now-problem – alecxe Mar 12 '14 at 04:18
  • I figured it out by myself. The reason is that, in mysql, I use timestamp for the time field when I created the table. But in Django, the field in the database is datetime. – user2443279 Mar 12 '14 at 04:30

0 Answers0