Django日期时间解析因遗留数据库而失败

时间:2012-10-06 16:12:51

标签: django datetime

我正在尝试使用digikam中的现有数据库,并为其创建一个DJango应用程序。但是在管理员中打开一个模型时,我会因为DateTimeField而遇到问题。

我使用了遗留数据库函数here的导入,它工作正常(我已经可以使用两个表)。生成的images表模型为:

class Image(models.Model):
    id = models.IntegerField(primary_key=True)
    album = models.IntegerField(null=True, blank=True)
    name = models.TextField()
    status = models.IntegerField()
    category = models.IntegerField()
    modificationdate = models.DateTimeField(null=True, db_column=u'modificationDate', blank=True) # Field name made lowercase.
    filesize = models.IntegerField(null=True, db_column=u'fileSize', blank=True) # Field name made lowercase.
    uniquehash = models.TextField(db_column=u'uniqueHash', blank=True) # Field name made lowercase.
    class Meta:
        db_table = u'Images'
    def __unicode__(self):
        return name

在调用相关的管理页面时,我得到一个“ValueError”,并且跟踪显示它正在尝试将字符串'2012-09-30T11:35:35'转换为日期时间。

两个问题

  1. 如果我设置modificationdate = models.TextField(...)错误仍然存​​在,并且仍然尝试将上述字符串转换为日期时间。为什么?
  2. 如果我在settings.py中为DATETIME_INPUT_FORMATS(即'%Y-%m-%dT%H:%M:%S')的元组添加拟合格式,则错误仍然存​​在。我如何让Django接受我的其他格式?
  3. 使用Django 1.3.1和sqlite3。删除行modificationdate = ...可以解决问题。

0 个答案:

没有答案