我有以下領域對我Django
型號:轉換時間字符串TimeField
ValidationError:[U「'36 0.332的價值有一個無效的格式必須是HH:MM [:SS [.uuuuuu] ]格式「]
from django.db import models
class TestSuite(models.Model):
time = models.TimeField()
當我分析我的.xml
測試報告文件,我有以下領域:
'time': u'36.332'
當我嘗試通過創建模型3210我看到了以下錯誤:
kwargs = {'time': u'36.332'}
testsuite = TestSuite(**kwargs)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 710, in save
force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 738, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 822, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 861, in _do_insert
using=using, raw=raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 920, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 970, in execute_sql
for sql, params in self.as_sql():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 928, in as_sql
for obj in self.query.objs
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 710, in get_db_prep_save
prepared=False)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 2293, in get_db_prep_value
value = self.get_prep_value(value)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 2288, in get_prep_value
return self.to_python(value)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 2275, in to_python
params={'value': value},
ValidationError: [u"'36.332' value has an invalid format. It must be in HH:MM[:ss[.uuuuuu]] format."]
如何將我的字符串轉換'time'
爲TimeField()
對象? *注:* '36.332'
意味着36.332 seconds
它應該表示什麼? 36.3什麼? –
@DanielRoseman更新了問題 – cybertextron
您可能不希望使用'TimeField'來表示秒數。 'TimeField'用於存儲一天的特定時間,而不是'timedelta'。在Django 1.8中,你會使用'DurationField'。在以前的版本中,將它作爲一個數字字段存儲,無論您關心的是什麼級別的精度,或者使用第三方字段實現之一 - 請參閱一些鏈接的答案:http://stackoverflow.com/questions/801912/ how-to-put-time-delta-in-django-model –