我对djanggo 1.7有问题,我使用python 2.7
这个代码在models.py
中class Tag(models.Model):
title = models.CharField(max_length=50)
description = models.TextField()
created_date = models.DateTimeField(default = timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
class Post(models.Model):
author = models.ForeignKey('auth.User')
category = models.ForeignKey(Category)
tag = models.ForeignKey(Tag)
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default = timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
这是urls.py
from django.conf.urls import patterns, include, url
from . import views
urlpatterns = patterns('',
url(r'^$', views.post_list),
url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail),
url(r'^post/new/$', views.post_new, name='post_new'),
url(r'^post/(?P<pk>[0-9]+)/edit/$', views.post_edit, name='post_edit'),
)
我成功完成了迁移,但是当我尝试/manage.py迁移时,我会收到这样的错误
TypeError: int() argument must be a string or a number, not 'datetime.date'
你可以帮我解决这个问题吗?
答案 0 :(得分:1)
而不是models.DateTimeField(default = timezone.now)
尝试models.DateTimeField(auto_now_add=True)